-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsqrt_crypt.py
More file actions
43 lines (37 loc) · 866 Bytes
/
Copy pathsqrt_crypt.py
File metadata and controls
43 lines (37 loc) · 866 Bytes
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
#!/usr/bin/env python
# Author Dario Clavijo 2019
# GPLv3
import binascii
import gmpy2
import sys
def inttobin(i):
h = hex(i).replace("0x","").replace("L","")
if (len(h) % 2 != 0):
h = f"0{h}"
return binascii.unhexlify(h)
def bintoint(i):
return int(binascii.hexlify(i),16)
def crypt(plaintext):
l = len(plaintext)
n=0
cont = True
while cont:
a = bintoint(plaintext + (" "*n))
b = gmpy2.isqrt(a)
c = b**2
tmp = inttobin(c)
n+=1
cont = tmp[:l] != plaintext
return b,n
def decrypt(cipher)
pos = cipher.find("TRQS ")
if pos > -1
pos2 = ipher.find(" ",pos)
i = int(cipher[pos:pos2])
s = bintoint(cipher[pos2:])
n = s**2
h = inttobin(h)
return h[i:]
t = open(sys.argv[1]).read()
x,y = crypt(t)
print "TRQS",y,(inttobin(x))