fork(1) download
  1. size = input("Matrix size: ")
  2. size = int(size)
  3. print()
  4. phrase = input("Chifer phrase (size = "+str(size*size)+"): ")
  5. print()
  6. keyV = input("Key (size= "+str(size)+"): ")
  7. print()
  8. print()
  9.  
  10. emptyMatrix = []
  11. for i in list(range(size)):
  12. emptyMatrix.append([])
  13. for j in list(range(size)):
  14. emptyMatrix[i].append("-")
  15.  
  16. matrix = list(emptyMatrix)
  17.  
  18. for i in list(range(size)):
  19. for j in list(range(size)):
  20. matrix[i][j]=phrase[size*j+i]
  21.  
  22. keyOrdV = []
  23. for i in list(range(size)):
  24. keyOrdV.append(ord(keyV[i]))
  25.  
  26. newKeyOrdV = []
  27. for i in list(range(size)):
  28. newKeyOrdV.append(keyOrdV.index(min(keyOrdV)))
  29. keyOrdV[newKeyOrdV[i]]=9999
  30.  
  31. finalMatrix = list(emptyMatrix)
  32.  
  33. for i in list(range(size)):
  34. j=0
  35. for j in list(range(size)):
  36. k=newKeyOrdV[j]
  37. print(str(matrix))
  38. finalMatrix[i][j] = matrix[i][newKeyOrdV[j]]
  39. print("MAGIC")
  40. print(str(matrix))
  41. print()
  42.  
  43. print()
  44. print("Debug info:")
  45. print(str(matrix))
  46. print(str(newKeyOrdV))
  47. print(str(finalMatrix))
  48. print()
  49.  
  50. finStr = ""
  51. for i in list(range(size)):
  52. for j in list(range(size)):
  53. finStr = finStr + finalMatrix[i][j]
  54.  
  55. print("Cifered phrase: "+finStr)
  56.  
Success #stdin #stdout 0.03s 9440KB
stdin
2
abcd
pi
stdout
Matrix size: 
Chifer phrase (size = 4): 
Key (size= 2): 

[['a', 'c'], ['b', 'd']]
MAGIC
[['c', 'c'], ['b', 'd']]

[['c', 'c'], ['b', 'd']]
MAGIC
[['c', 'c'], ['b', 'd']]

[['c', 'c'], ['b', 'd']]
MAGIC
[['c', 'c'], ['d', 'd']]

[['c', 'c'], ['d', 'd']]
MAGIC
[['c', 'c'], ['d', 'd']]


Debug info:
[['c', 'c'], ['d', 'd']]
[1, 0]
[['c', 'c'], ['d', 'd']]

Cifered phrase: ccdd