from hilbertcurve.hilbertcurve import HilbertCurve import matplotlib.pyplot as plt n = 2 p = 5 pts = {} stp = {} key = int(input("enter key length here: ")) numberizer = { "~" : -1, "a" : 0, "b" : 1, "c" : 2, "d" : 3, "e" : 4, "f" : 5, "g" : 6, "h" : 7, "i" : 8, "j" : 9, "k" : 10, "l" : 11, "m" : 12, "n" : 13, "o" : 14, "p" : 15, "q" : 16, "r" : 17, "s" : 18, "t" : 19, "u" : 20, "v" : 21, "w" : 22, "x" : 23, "y" : 24, "z" : 25, " " : 26, "1" : 27, "2" : 28, "3" : 29, "4" : 30, "5" : 31 } unnumberizer = { -1 : "~", 0 : "a", 1 : "b", 2 : "c", 3 : "d", 4 : "e", 5 : "f", 6 : "g", 7 : "h", 8 : "i", 9 : "j", 10 : "k", 11 : "l", 12 : "m", 13 : "n", 14 : "o", 15 : "p", 16 : "q", 17 : "r", 18 : "s", 19 : "t", 20 : "u", 21 : "v", 22 : "w", 23 : "x", 24 : "y", 25 : "z", 26 : " ", 27 : "1", 28 : "2", 29 : "3", 30 : "4", 31 : "5" } #y is place in plaintext #x is letter/number plaintext = input("Enter plain text here: ") plainlength = -1 mediumtext = [] for element in plaintext.lower(): plainlength += 1 plainlength = plainlength % 31 if plainlength == 0: mediumtext.append((-1,-1)) mediumtext.append((numberizer[element],plainlength)) print(mediumtext) hilbert_curve = HilbertCurve(p,n) totalpoints = 2**(p*n) distances = list(range(totalpoints)) #distances = list(range(int(input("list the number of points")))) points = hilbert_curve.points_from_distances(distances) n = -1 for x, y in points: #xs.append(x/(2**p-1)) #ys.append(y/(2**p-1)) #print(str((x/(2**p-1))) + ", " + str((y/(2**p-1)))) n += 1 pts[(x,y)] = n stp[n] = (x,y) endtext = [] for element in mediumtext: if element != (-1,-1): a = pts[element] + key a = a % 1023 endtext.append(stp[a]) else: endtext.append((-1,-1)) print(endtext) ciphertext = "" for element in endtext: ciphertext += (str((unnumberizer[element[0]]) + str(unnumberizer[element[1]]))) print(ciphertext)