计算Android屏幕解锁组合数
晚饭时和同事聊到安卓屏幕解锁时会有多少种解锁方案,觉得很有趣,吃完饭开始想办法解题,花了大概2个小时解决。思路如下:
- 使用索引值0-9表示从左到右、从上到下的9个点,行、列号很容易从索引值得到;
- 使用一个列表(routeList)来表示解锁路径,列表的元素为点的索引值;
- 从任意点N出发(将index(N)放入routeList),判断与哪些点(集合NextNodes)可以构成合法路径;然后用递归的方式从NextNodes中的点出发,寻找下一个可以构成合法路径的点;直到再也无法找到可用的点供路径使用
下一步,就是在Nexus 7上捣鼓,发现Android定义合法的解锁路径必须满足下列条件:
- 构成路径的点不得少于4个
- 路径中不能有重复的点
- (这点有点绕口)构成边或对角线的两点(例如[0,2]构成边,[0,8]构成对角线),不能在路径中相邻,除非其中点已经在路径中出现
接下来就是写代码了,Let's talk with the code!
问题的解是:389112
1 ############################################################### 2 ####### AndrUlkComb.py ######### 3 ## Calculate the COMBination count for ANDroid UNLock screen ## 4 ## By grepall@gmail.com ## 5 ############################################################### 6 7 8 ############################################################### 9 ## The Android unlock screen looks like below 10 ## ------------------------------- 11 ## o -> o -> o 12 ## 13 ## o o o 14 ## 15 ## o o o 16 ## -------------------------------- 17 ## 18 ## We'll use: 19 ## 1. Index from 0-8 to represent all 9 nodes instead of 20 ## using row:column format. 21 ## 2. An array (routeList in the code) to record the path of the unlock combination. 22 ## For example, for the unlock comb which is shown in 23 ## in the figure. There will be 3 elements in the array: 24 ## 0, 1, and 2. (Although it's NOT a valid path because of 25 ## not long enough) 26 ## 27 ## Valid unlock path must holds true for 3 conditions: 28 ## C1: It must pass 4 different nodes at least; 29 ## C2: It cannot contains duplicate nodes; 30 ## C3: This is a little tricky. Any node cannot direct link to another node, when 31 ## any node will be past through if we connect those 2 nodes in the unlock panel. UNLESS 32 ## the crossed node already EXISTs in the path. 33 ## For example, path (0, 2, 5, 4) is not valid, because 0-->2 crosses node 1. But path 34 ## (1, 0, 2, 5) is a vliad path. 35 ## This rule holds for diagonal as well. 36 37 38 39 ####################################################################### 40 # M stands for the width of the unlock panel 41 # H stands for the height of the unlock panel 42 # CAUTION: Modify this value will NOT generate correct result!!! That's TO BE DONE 43 # 44 W = 3 #Width 45 H = 3 #Height 46 47 # Unlock path 48 routeList = list() 49 50 # Combination count, which is we want to know 51 routeCount = 0 52 53 54 55 def isValidRoute(p1, route): 56 # If the candidate node exists in the unlock path 57 if route.count(p1) != 0: 58 return False 59 return True; 60 61 62 def isCrossPoint(p1, p2): 63 # Will the connection line (p1, p2) cross another node? 64 x1 = p1%W 65 y1 = p1/W 66 x2 = p2%W 67 y2 = p2/W 68 if x1 == x2 and abs(y1-y2) > 1: 69 return True # same column 70 if y1 == y2 and abs(x1-x2) > 1: 71 return True # same row 72 if abs(y1-y2) == abs(x1-x2) and abs(y1-y2)>1: 73 return True # diagonal 74 return False 75 76 def tryPoint(lastPt, route): 77 # Try next valid node for the unlock path recursively 78 global routeCount 79 for pt in range(0, W*H): 80 if isValidRoute(pt, route): #C2 81 crossPt = (lastPt+pt)/2 82 if isCrossPoint(lastPt, pt) and route.count(crossPt) == 0: #C3 83 continue 84 route.append(pt) 85 if len(route) >3: #C1 86 routeCount += 1 87 tryPoint(pt, route) 88 route.pop() 89 90 91 # Each node may be the start node for unlock 92 for i in range(0, W*H): 93 routeList = [i] 94 tryPoint(i, routeList) 95 print "Start from point %d, combination count is %d now..." % (i, routeCount) 96 print "Toatl combination counter for Android unlock screen: " + str(routeCount)
View Code
转载于:https://www.cnblogs.com/grepall/p/3160096.html
计算Android屏幕解锁组合数相关推荐
- Android屏幕解锁图案破解
标 题: [原创]Android屏幕解锁图案破解 作 者: gamehacker 时 间: 2013-03-27,14:29:58 链 接: http://bbs.pediy.com/showthre ...
- 【移动安全实战篇】————5、Android屏幕解锁图案破解
Android手机上有一个屏幕解锁的应用相信大家都不陌生,在 Android 设备上,用户可以通过设置锁定图案作为密码对设备用户界面进行锁定,锁定界面如下图所示. 一般的Android手机的锁定界面由 ...
- android屏幕解锁新解
最近因为一些事接触到android屏幕解锁这块,刚开始查询网上资料,绝大部分以keyguardLock 来进行获取屏幕锁和接触屏幕锁,其思路如下: // KeyguardManager keyguar ...
- android屏幕解锁新思路
最近接了个私活,涉及到屏幕解锁,由于从来没接触过这块方面的知识,网上找了很多相关的内容,基本上都是以 private PowerManager.WakeLock wl; private Keyguar ...
- android屏幕解锁图案,安卓手机图案屏幕锁解锁方法!!
当你的安卓手机密码锁忘记了怎么办?今天一不小心把手机改了图案锁结果由于改的时候匆忙结果忘记了,在网上找了好多方法都无果,也有人说重新刷机就会好!!这个简直就是废话,刷机当然能好了!! 关键是解锁要解决 ...
- Android屏幕解锁和点亮
有些场景需要程序自动点亮屏幕,解开屏幕锁,以方便用户即时操作,下面用代码来实现这一功能: 1.//得到键盘锁管理器对象 2.KeyguardManager km= (KeyguardManager) ...
- 仿写Android屏幕解锁小应用
近日需要设置密码并加密,因此仿写了Android的位置和安全设置有更改屏幕锁定的设置.先看效果图: 点击后,第一次是可设置密码. 设置成功密码后再点Button按钮将会出现: 由于时间紧,因此只研究了 ...
- Android点亮屏幕或屏幕解锁和锁定
1.Android屏幕常亮/点亮 //保持屏幕常亮 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); ...
- 4个顶级的华为/小米/OPPO/Vivo手机屏幕解锁工具软件
有好几次用户发现自己被锁定在他们的华为/小米/OPPO/Vivo设备之外,我们知道这可能是一种非常可怕的体验.在这种情况下,找到安卓手机解锁软件,重新获得手机中重要数据和文件的访问权限.看看这篇文章, ...
最新文章
- form 提交多个对象及springMVC接收
- 入门Web前端有哪些误区?该如何避免?
- php 连接数据库 pod,PHP PDO类解决数据库连接问题
- WIN7情况下VMWARE虚构机中Microsoft Windows XP Professional 2002 Service Pack2与win7共享文件的编制:
- 简易计算机系统综合设计设计报告(VHDL)
- SpringCloud学习之Hystrix
- [IE编程] IE8的SDK 下载
- busybox的使用
- IIS5.1、IIS6.0、IIS7.5中安装配置MVC 3
- 一种基于复制粘贴的cam350邮票孔拼版教程(二)导出gerber
- vue路由变化时使用axios取消所有请求
- 关于慧斯顿电桥的疑惑
- 群晖DOCKER搭建自动签到 PT网站再也不怕忘记登录了
- python uppercase函数_字符串-短rot13函数-Python
- readability: 英文文本数据可读性库
- Android界面开发基础
- 多网站如何共用一个微信
- 一种根据EI检索结果对比CCF期刊/会议评级的程序
- 关键词:MAU,DAU,DAU/MAU
- c语言稀疏矩阵_C中的稀疏矩阵