daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Feb 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from string import ascii_lowercase
  2. from collections import deque
  3.  
  4. alphabetToNumbers = dict()
  5. alphabetToNumbers["A"] = 0
  6. alphabetToNumbers['B'] = 1
  7. alphabetToNumbers['C'] = 2
  8. alphabetToNumbers['D'] = 3
  9. alphabetToNumbers['E'] = 4
  10. alphabetToNumbers['F'] = 5
  11. alphabetToNumbers['G'] = 6
  12. alphabetToNumbers['H'] = 7
  13. alphabetToNumbers['I'] = 8
  14. alphabetToNumbers['J'] = 9
  15. alphabetToNumbers['K'] = 10
  16. alphabetToNumbers['L'] = 11
  17. alphabetToNumbers['M'] = 12
  18. alphabetToNumbers['N'] = 13
  19. alphabetToNumbers['O'] = 14
  20. alphabetToNumbers['P'] = 15
  21. alphabetToNumbers['Q'] = 16
  22. alphabetToNumbers['R'] = 17
  23. alphabetToNumbers['S'] = 18
  24. alphabetToNumbers['T'] = 19
  25. alphabetToNumbers['U'] = 20
  26. alphabetToNumbers['V'] = 21
  27. alphabetToNumbers['W'] = 22
  28. alphabetToNumbers['X'] = 23
  29. alphabetToNumbers['Y'] = 24
  30. alphabetToNumbers['Z'] = 25
  31.  
  32. numbersToAlphabet = dict()
  33. numbersToAlphabet[0] = 'A'
  34. numbersToAlphabet[1] = 'B'
  35. numbersToAlphabet[2] = 'C'
  36. numbersToAlphabet[3] = 'D'
  37. numbersToAlphabet[4] = 'E'
  38. numbersToAlphabet[5] = 'F'
  39. numbersToAlphabet[6] = 'G'
  40. numbersToAlphabet[7] = 'H'
  41. numbersToAlphabet[8] = 'I'
  42. numbersToAlphabet[9] = 'J'
  43. numbersToAlphabet[10] = 'K'
  44. numbersToAlphabet[11] = 'L'
  45. numbersToAlphabet[12] = 'M'
  46. numbersToAlphabet[13] = 'N'
  47. numbersToAlphabet[14] = 'O'
  48. numbersToAlphabet[15] = 'P'
  49. numbersToAlphabet[16] = 'Q'
  50. numbersToAlphabet[17] = 'R'
  51. numbersToAlphabet[18] = 'S'
  52. numbersToAlphabet[19] = 'T'
  53. numbersToAlphabet[20] = 'U'
  54. numbersToAlphabet[21] = 'V'
  55. numbersToAlphabet[22] = 'W'
  56. numbersToAlphabet[23] = 'X'
  57. numbersToAlphabet[24] = 'Y'
  58. numbersToAlphabet[25] = 'Z'
  59.  
  60.  
  61. def generateMatrix(stringToHash):
  62.     if (len(stringToHash) > 16):
  63.         raise Exception('error in generateMatrix: stringToHash should not exceed 16 characters')
  64.     i = 0
  65.     matrix = []
  66.     row = []
  67.     for s in stringToHash:
  68.         i = i + 1
  69.         row.append(s)
  70.         if (i == 4):
  71.             matrix.append(row)
  72.             i = 0
  73.             row = []
  74.     return matrix
  75.  
  76. def generateIndexMatrix(matrix):
  77.     idxMatrix = []
  78.     idxRow = []
  79.     i = 0
  80.     for row in matrix:
  81.         for letter in row:
  82.             i = i + 1
  83.             idxRow.append(alphabetToNumbers.get(letter))
  84.             if (i == 4):
  85.                 idxMatrix.append(idxRow)
  86.                 i = 0
  87.                 idxRow = []
  88.     return idxMatrix
  89.  
  90. def addColumns(matrix, tup):
  91.     (first,second,third,fourth) = tup
  92.     print(matrix)
  93.     col1 = (matrix[0][0] + matrix[1][0] + matrix[2][0] + matrix[3][0]) % 26
  94.     col2 = (matrix[0][1] + matrix[1][1] + matrix[2][1] + matrix[3][1]) % 26
  95.     col3 = (matrix[0][2] + matrix[1][2] + matrix[2][2] + matrix[3][2]) % 26
  96.     col4 = (matrix[0][3] + matrix[1][3] + matrix[2][3] + matrix[3][3]) % 26
  97.  
  98.     return ((first+col1) % 26, (second+col2) % 26, (third + col3) % 26, (fourth+col4) % 26)
  99.  
  100. def shiftMatrix(matrix):
  101.     #Shift first by 1
  102.     rowOne = deque(matrix[0])
  103.     rowTwo = deque(matrix[1])
  104.     rowThree = deque(matrix[2])
  105.     rowFour = deque(matrix[3])
  106.     rowOne.rotate(-1)
  107.     rowTwo.rotate(-2)
  108.     rowThree.rotate(-3)
  109.     rowFour.reverse()
  110.     return [list(rowOne), list(rowTwo), list(rowThree), list(rowFour)]
  111.    
  112. hashString = "ILEAVEAAAAAAMILLIONAAAAAAATOAAFRIENDLYCOUSINAAAA"
  113. matrix = generateMatrix(hashString[0:16])
  114. print("Hashing:..." + hashString[0:16] +"\n")
  115. idxMatrix = generateIndexMatrix(matrix)
  116. columns = addColumns(idxMatrix, (0,0,0,0))
  117.  
  118. matrix = shiftMatrix(matrix)
  119. idxMatrix = generateIndexMatrix(matrix)
  120. columns = addColumns(idxMatrix, columns)
  121. print(columns)
  122.  
  123.  
  124. matrix = generateMatrix(hashString[16:32])
  125. print("Hashing:..." + hashString[16:32] +"\n")
  126. idxMatrix = generateIndexMatrix(matrix)
  127. columns = addColumns(idxMatrix, columns)
  128.  
  129. matrix = shiftMatrix(matrix)
  130. idxMatrix = generateIndexMatrix(matrix)
  131. columns = addColumns(idxMatrix, columns)
  132.  
  133. matrix = generateMatrix(hashString[32:48])
  134. print("Hashing:..." + hashString[32:48] +"\n")
  135. idxMatrix = generateIndexMatrix(matrix)
  136. columns = addColumns(idxMatrix, columns)
  137.  
  138. matrix = shiftMatrix(matrix)
  139. idxMatrix = generateIndexMatrix(matrix)
  140. (a,b,c,d) = addColumns(idxMatrix, columns)
  141.  
  142.  
  143.  
  144. print("Hash is: " + numbersToAlphabet.get(a) + numbersToAlphabet.get(b) + numbersToAlphabet.get(c) + numbersToAlphabet.get(d))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top