当前位置:网站首页>判断密码是否包含键盘连续字母
判断密码是否包含键盘连续字母
2022-08-04 12:29:00 【格格巫 MMQ!!】
新增内容为增加键盘列排序检测。
原理:
用两个与传入密码长度相等的一维数组(Row行数组,Column列数组)
按密码顺序在二维键盘数组中查找每个字符,找到了则用
一维行列数组分别存放密码中每个字符的行号和列号
然后循环分析行号和列号是否满足二维键盘数组的值来判断是否连续
BOOL IsKeyBoardContinuousChar( LPCTSTR lpStr )
{
if ( lpStr == NULL || _tcslen(lpStr) == 0 )
{
return FALSE;
}
// 注意,下面的键盘字符表都只列出小写字符,判断前会将输入字符中的
// 大写字母都转换成小写字母
// 非shift键盘字符表
TCHAR aaCharTable1[4][13] =
{ ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘0’, ‘-’, ‘=’, ‘\0’,
‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’, ‘u’, ‘i’, ‘o’, ‘p’, ‘[’, ‘]’, ‘\’,
‘a’, ‘s’, ‘d’, ‘f’, ‘g’, ‘h’, ‘j’, ‘k’, ‘l’, ‘;’, ‘’', ‘\0’, ‘\0’,
‘z’, ‘x’, ‘c’, ‘v’, ‘b’, ‘n’, ‘m’, ‘,’, ‘.’, ‘/’, ‘\0’, ‘\0’, ‘\0’,
};
// 包含shift键盘的字符表
TCHAR aaCharTable2[4][13] =
{ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', '\0', '\0',
'z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?', '\0', '\0', '\0'
};
// 获取坐标位置
int nStrLen = _tcslen( lpStr );
// 定义位置数组
// row - 行,col - column 列
int* pRowCharPos = new int[nStrLen];
int* pColCharPos = new int[nStrLen];
for (int i = 0; i < nStrLen; i++)
{
pRowCharPos[i] = 0; // 行索引
pColCharPos[i] = -1; // 列索引
// 考虑大小写,都转换成小写字母
TCHAR chLower = lpStr[i];
if ( chLower >= 'A' && chLower <= 'Z' )
{
chLower += 32;
}
// 检索在表1中的位置,构建位置数组
for ( int nRowTable1Idx = 0; nRowTable1Idx < 4; nRowTable1Idx++ )
{
for ( int nColTable1Idx = 0; nColTable1Idx<13; nColTable1Idx++ )
{
if ( chLower == aaCharTable1[nRowTable1Idx][nColTable1Idx] )
{
pRowCharPos[i] = nRowTable1Idx;
pColCharPos[i] = nColTable1Idx;
}
}
}
// 在表1中没找到,到表二中去找,找到则continue
if ( pColCharPos[i] != -1 )
{
continue;
}
// 检索在表2中的位置,构建位置数组
for ( int nRowTable2Idx = 0; nRowTable2Idx < 4; nRowTable2Idx++ )
{
for (int nColTable2Idx = 0; nColTable2Idx<13; nColTable2Idx++ )
{
if ( chLower == aaCharTable2[nRowTable2Idx][nColTable2Idx] )
{
pRowCharPos[i] = nRowTable2Idx;
pColCharPos[i] = nColTable2Idx;
}
}
}
}
// 匹配坐标连线
for ( int j = 1; j <= nStrLen-2; j++ )
{
//同一行
if (pRowCharPos[j - 1] == pRowCharPos[j] && pRowCharPos[j] == pRowCharPos[j + 1])
{
// 键盘行连续(asd)或者键盘行反向连续(dsa)
if ( (pColCharPos[j - 1] + 1 == pColCharPos[j] && pColCharPos[j] + 1 == pColCharPos[j + 1]) ||
(pColCharPos[j + 1] + 1 == pColCharPos[j] && pColCharPos[j] + 1 == pColCharPos[j - 1]) )
{
return TRUE;
}
}
//新增内容
//同一列
if (pColCharPos[k - 1] == pColCharPos[k] && pColCharPos[k] == pColCharPos[k + 1])
{
//键盘列连续(qaz)或者键盘列反向连续(zaq)
if ((pRowCharPos[k - 1] + 1 == pRowCharPos[k] && pRowCharPos[k] + 1 == pRowCharPos[k + 1]) ||
(pRowCharPos[k - 1] - 1 == pRowCharPos[k] && pRowCharPos[k] - 1 == pRowCharPos[k + 1]))
{
return TRUE;
}
}
}
return FALSE;
}
看图解码

判断密码是否连续3个及以上重复或者字母连续
for (int i = 0; i <strlen(newPassword) - 2; i++)
{
int n1 = int(newPassword[i]);
int n2 = int(newPassword[i+1]);
int n3 = int(newPassword[i+2]);
// 判断重复字符
if (n1 == n2 && n1 == n3)
{
return TRUE;
}
// 判断连续字符: 正序 + 倒序
if ((n1 + 1 == n2 && n1 + 2 == n3) || (n1 - 1 == n2 && n1 - 2 == n3))
{
return TRUE;
}
}
return FALSE;
边栏推荐
- Do you understand the various configurations in the project?
- Why is Luo Zhenyu's A-share dream so difficult to fulfill?
- 聚焦数据来源、数据质量和模型性能构建小微企业信用画像
- Tarjan 求有向图的强连通分量
- 用VbScript控制光驱
- 面试官:连 INSERT INTO SET 都不知道怎么用,你这3年都干些什么了?
- Neck modules of the yolo series
- 【PHP实现微信公众平台开发—基础篇】第2章 微信公众账号及申请流程详解
- 广告电商系统开发之订单处理
- 一分钟认识 IndexedDB 数据库,太强大了!
猜你喜欢

外置USB供电与内置锂电池供电自动切换电路

Share | technology integration electronic fence function of scheduling system

DC/DC电感底部要不要覆铜?

UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!

酷开科技 × StarRocks:统一 OLAP 分析引擎,全面打造数字化的 OTT 模式

简要介绍电源效率测试

DC-DC电源中前馈电容的选择

LeetCode每日一题(858. Mirror Reflection)

MySQL - Explain详解

如何治理资源浪费?百度云原生成本优化最佳实践
随机推荐
Why is Luo Zhenyu's A-share dream so difficult to fulfill?
ShanDong Multi-University Training #4 A、B、C、G
基于BiLSTM的回归预测方法
如何做好企业数字化转型?这10份靠谱案例收藏了(附下载)
全面认识MOS管,一篇文章就够了
小程序在政务服务平台建设中如何发挥价值
oracle sql中根据条件判断是否插入数据
Valentine's Day Romantic 3D Photo Wall [with source code]
Chinese valentine's day of young people crazy to make money, earn 140000 a week
一分钟认识 IndexedDB 数据库,太强大了!
【微信小程序】信息管理与信息系统专业社会实习制作项目--垃圾指纹
【Game Of AutoTest】1、再度启程,重识游戏自动化测试
情人节浪漫3D照片墙【附源码】
MySQL必知必会(初级篇)
Motion Rule (16)-Union Check Basic Questions-Grid Game
Oracle 19c 单实例 19.3.0 升级到19.11.0 详细教程
第10章 模块和包
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
拥有一台服务器,程序猿装X的开始
Share | technology integration electronic fence function of scheduling system