CTF encryption and decryption supplement

Your pub has smashed me, and the bullets are on my mind

I made a few CTF encryption and decryption questions today, and posted some common password decryption codes in CTF. As I have summarized some before, see: [CTF Encryption and Decryption] (https://thief.one/%2F2017%2F06%2F13%2F1%2F), so this article mainly supplements some encryption methods that were not mentioned before.

01248 Password

Principle

The password uses four numbers 1, 2, 4, and 8, where 0 is used to indicate the interval, and other numbers are represented by addition, such as: 28=10,124=7,18=9, and then 1->26 means A- >Z conversion can be.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
dict_ = {}
for i in xrange(1,27):
dict_[i]=chr(i+64)
def decode(str_):
str_new = ""
list_ = str_.split("0")
for i in list_:
number = 0
for j in i:
number+=int(j)
str_new+=dict_.get(number)
return str_new
if __name__=="__main__":
str_ = "8842101220480224404014224202480122"
print decode(str_)

Reference: https://wiki.x10sec.org/crypto/classical/others/#01248

QWE password

Principle

Computer keyboard QWE encryption is to replace the order of the keyboard with the alphabet.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
str1="QWERTYUIOPASDFGHJKLZXCVBNM"
str2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def qwe_encode(en_str):
str3 = ""
for s in en_str:
str3=str3+str1[str2.index(s.upper())]
return str3
def qwe_decode(de_str):
str3 = ""
for s in de_str:
str3=str3+str2[str1.index(s.upper())]
return str3
if __name__=="__main__":
print qwe_decode("OOSNGQCFTWLQIK")
print qwe_encode("IILYOAVNEBSAHR")

Reference: https://www.cnblogs.com/ssooking/p/6559935.html

Hill password

Principle

[Baidu Encyclopedia] (https://baike.baidu.com/item/%E5%B8%8C%E5%B0%94%E5%AF%86%E7%A0%81?fr=aladdin)

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from numpy import *
Dic = {chr(i+97):i for i in range(26)}
def decode_2(pwd='dloguszijluswogaqy',org=[[1,2],[0,1]]):
''' Two-dimensional matrix '''
key=mat(org)
Key1=key.I.T #key undergoes an inverse operation and then performs a transposition
finalans = ''
str2=[0 for i in range(len(pwd))]
for i in range(len(pwd)):
str2 [i] = words (pwd [i]) - word ( 'a') + 1
# Convert a string to a number in the hill password
num = len (str2) 4%
for i in range(4-num):
str2.append(0)
#To get the numbers above to make up the number, to ensure that four can be a group, to facilitate the calculation later
count=0
for i in range(len(str2)/4):
crypto1=mat([[str2[count],str2[count+1]],[str2[count+2],str2[count+3]]])
# Take 4 as a group and take each group of ciphertext separately
Ans=(crypto1*key1)%26 #calculate plaintext
Ans2=array(ans) #here is the standard form of converting ans into a matrix, so that you can get out every number
count+=4
for m in range(2):
for n in range(2):
finalans+=chr(int(ans2[m][n])+ord('a')-1)
# Convert plaintext to a string
finalans = finalans.replace ("` "," ")
return finalans
def decode_3(pwd="wjamdbkdeibr", org=[[1,2,3],[4,5,6],[7,8,10]]):
''' 3D matrix '''
pwd = list(pwd)
org_ = matrix(array(org))
org = get_vmatrix(org_)
temp = []
result = []
while True:
if len(pwd) % 3 != 0:
pwd.append(pwd[-1])
else:
break
for i in pwd:
temp.append(Dic.get(i))
temp = array(temp)
temp = temp.reshape(len(pwd)/3, 3)
xx = matrix(temp)*org
for j in range(len(pwd)/3):
for i in range(3):
if (int(xx[j, i]) >= 26):
result.append(chr(xx[j, i] % 26 + 97))
else:
result.append(chr(xx[j, i] + 97))
return "".join(result)
def get_vmatrix(org):
org_adjoin = org.I*linalg.det(org)
org_det = int (str (abs (linalg.the (org))) split ('.') [0])
for i in range(1, 26):
if i * org_det % 26 == 1:
break
org_mod = -org_adjoin * i % 26
org_mod = matrix(org_mod)
temp = []
for i in range(org_mod.shape[0]):
for j in range(org_mod.shape[1]):
temp.append(int(str(org_mod[i, j]).split('.')[0]))
org_final = matrix(temp).reshape(org_mod.shape[0], org_mod.shape[1])
return org_final
if __name__ == '__main__':
print decode_2(pwd='dloguszijluswogaqy',org=[[1,2],[0,1]])
print decode_3(pwd="wjamdbkdeibr", org=[[1,2,3],[4,5,6],[7,8,10]])

Portal

[CTF Encryption and Decryption] (https://thief.one/%2F2017%2F06%2F13%2F1%2F)

本文标题:CTF encryption and decryption supplement

文章作者:nmask

发布时间:2019年07月24日 - 18:07

最后更新:2019年08月16日 - 15:08

原始链接:https://thief.one/2019/07/24/1/en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

nmask wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!

热门文章推荐: