Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Cipher Map - Numpy solution in 3rd party category for Cipher Map by Michal_Szajer
import numpy as np
def recall_password(cipher_grille, ciphered_password):
#First we have to declare 4x4 array with zeros as integers, we will later use this array(matrix) as a cipher_grille
grille_matrix = np.zeros([4,4], dtype=int)
#Second Step is to declare a string variable result, which later will contain the decyphered message
result = ""
'''
In the first loop we change the values of grille_matrix to correspond with cipher_grille.
For each X in cipher _grille, grille_matrix will have 1 in the same place and for each dot in cipher_grille, grille matrix will have 0
'''
for i in range(0,4):
for j in range(0,4):
if cipher_grille[i][j] == "X":
grille_matrix[i][j] = 1
else:
grille_matrix[i][j] = 0
'''
In the next loop we will rotate the grille_matrix over the ciphered_password 4 times. We will use rot90 function from numpy library.
We have imported numpy, because we wanted to use rot90 function on an array, both don't exist outside numpy library (as far as I know)
Rot90 rotates counterclockwise, that, why I am rotating (4-n) times for each step.
We use the following string property:
"any string" * 0 = "" (empty string)
"any string" * 1 = "any string" (the same string)
That's why we have prepared grille matrix earlier (to have zeros and ones as a matrix)
We perform this multiplication for each value from each row for each rotation, and for each step we add it's value to string variable - result, which is later returnedas the value of the function.
'''
for n in range(0,4):
for i in range(0,4):
for j in range(0,4):
result = result + (ciphered_password[i][j] * np.rot90(grille_matrix,4-n)[i][j])
return result
July 31, 2018