其实没什么可说的原理,就是把9键的字母对应到26键来,先看一下九键。
可以找到一点规律,如果我想使用‘c’的话,那么就需要按三下‘2’,其他字母同理,那么26键呢。
很直观的把数字对应到字母上,那么在26键上的字母表就是‘wertyuio’,由26键对应到9键的密码就是字母加上次数。
例如:
rrr ttt yyy iii ee www uuu ooo u i yyy
对应一下上面所说的内容,‘ooo’对应字母为键盘上的‘o’,所映射的数字是‘9’,三个‘o’表示次数,就是九键上按键‘9’的‘y’,同理,得到一串字符串。
i love crypto
加密、解密功能具备
#python3 num2 = 'abc' num3 = 'def' num4 = 'ghi' num5 = 'jkl' num6 = 'mno' num7 = 'pqrs' num8 = 'tuv' num9 = 'wxyz' def decrypt(c): #c = 'rr ee ttt ttt yyy' #keyboard = 'wertyuio' c = c.split(' ') m = '' for i in c: if 'w' in i: m += num2[len(i)-1] if 'e' in i: m += num3[len(i)-1] if 'r' in i: m += num4[len(i)-1] if 't' in i: m += num5[len(i)-1] if 'y' in i: m += num6[len(i)-1] if 'u' in i: m += num7[len(i)-1] if 'i' in i: m += num8[len(i)-1] if 'o' in i: m += num9[len(i)-1] return m def encrypt(m): #m = 'hello' m = m.replace(' ','') keyboard = 'wertyuio' c = '' for i in m: if i in num2: c += keyboard[0] * (num2.index(i) + 1) if i in num3: c += keyboard[1] * (num3.index(i) + 1) if i in num4: c += keyboard[2] * (num4.index(i) + 1) if i in num5: c += keyboard[3] * (num5.index(i) + 1) if i in num6: c += keyboard[4] * (num6.index(i) + 1) if i in num7: c += keyboard[5] * (num7.index(i) + 1) if i in num8: c += keyboard[6] * (num8.index(i) + 1) if i in num9: c += keyboard[7] * (num9.index(i) + 1) c += ' ' return c print('the cipher is:',encrypt('hello')) print('the text is:',decrypt('www uuu ooo u i yyy'))