Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from sympy.mpmath import mp
- def get_pi(n):
- mp.dps = (n+1)
- pi = mp.pi
- return str(pi-int(pi))[2:]
- f = open("translated.txt", "w")
- msg = "".join(sys.argv[1].split())
- parse_error = False
- pxmin = pxmax = pymin = pymax = 0
- for i in range(len(msg) / 4):
- try:
- x = int(msg[i*4:i*4+2],16)
- y = int(msg[i*4+2:i*4+4],16)
- except:
- parse_error = True
- break
- if i == 0:
- pxmin,pxmax = (x,)*2
- pymin,pymax = (y,)*2
- pxmin = x if x < pxmin else pxmin
- pymin = y if y < pymin else pymin
- pxmax = x if x > pxmax else pxmax
- pymax = y if y > pymax else pymax
- dim = pxmax * pymax
- if (dim != 0):
- print "generating key using %i digits of pi..." % dim
- pi = get_pi(dim)
- key = []
- c = 0
- d = 1
- header = "".join([ str(i % 10) for i in range(0,pxmax + 1) ])
- key.append(header)
- while c < len(pi):
- key.append(str( d % 10 ) + str( pi[c:c+pxmax] ))
- c += pxmax
- d += 1
- dec = ""
- i = 0
- for i in range(len(msg) / 4):
- try:
- x = int(msg[i*4:i*4+2], 16)
- y = int(msg[i*4+2:i*4+4], 16)
- except:
- parse_error = True
- break
- dec += str(key[y][x])
- i = 0
- text = ""
- while i < len(dec):
- if dec[i] == '1':
- num = dec[i:i+3]
- i += 3
- else:
- num = dec[i:i+2]
- i += 2
- text += "%c" % int(num)
- f.write( text )
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement