Advertisement
Guest User

a858 decrypter

a guest
Aug 28th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import sys
  2. from sympy.mpmath import mp
  3.  
  4. def get_pi(n):
  5. mp.dps = (n+1)
  6. pi = mp.pi
  7. return str(pi-int(pi))[2:]
  8.  
  9.  
  10. f = open("translated.txt", "w")
  11. msg = "".join(sys.argv[1].split())
  12. parse_error = False
  13. pxmin = pxmax = pymin = pymax = 0
  14. for i in range(len(msg) / 4):
  15. try:
  16. x = int(msg[i*4:i*4+2],16)
  17. y = int(msg[i*4+2:i*4+4],16)
  18. except:
  19. parse_error = True
  20. break
  21.  
  22. if i == 0:
  23. pxmin,pxmax = (x,)*2
  24. pymin,pymax = (y,)*2
  25.  
  26. pxmin = x if x < pxmin else pxmin
  27. pymin = y if y < pymin else pymin
  28. pxmax = x if x > pxmax else pxmax
  29. pymax = y if y > pymax else pymax
  30.  
  31. dim = pxmax * pymax
  32.  
  33. if (dim != 0):
  34. print "generating key using %i digits of pi..." % dim
  35. pi = get_pi(dim)
  36. key = []
  37. c = 0
  38. d = 1
  39. header = "".join([ str(i % 10) for i in range(0,pxmax + 1) ])
  40. key.append(header)
  41. while c < len(pi):
  42. key.append(str( d % 10 ) + str( pi[c:c+pxmax] ))
  43. c += pxmax
  44. d += 1
  45.  
  46. dec = ""
  47. i = 0
  48. for i in range(len(msg) / 4):
  49. try:
  50. x = int(msg[i*4:i*4+2], 16)
  51. y = int(msg[i*4+2:i*4+4], 16)
  52. except:
  53. parse_error = True
  54. break
  55. dec += str(key[y][x])
  56.  
  57.  
  58. i = 0
  59. text = ""
  60. while i < len(dec):
  61. if dec[i] == '1':
  62. num = dec[i:i+3]
  63. i += 3
  64. else:
  65. num = dec[i:i+2]
  66. i += 2
  67. text += "%c" % int(num)
  68. f.write( text )
  69. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement