def decrypt(self, ciphertext, key): plaintext = '' numKey = [] self.generateLetterMatrix() ciphertext = cv.textToNum(ciphertext) numKey = cv.textToNum(key) counter = 0 #za svaki znak u šifratu for cipherletter in ciphertext: if (counter >= len(key)): counter = 0 #pronađi slovo koje uz ključ indeksira polje vigenereovog kvadrata #čiji je element odgovarajući znak šifrata. for letter in self.alphabet: if (cipherletter == self.alphabet.index(self.letter_matrix[ self.alphabet.index(letter)][numKey[counter]])): plaintext += letter counter += 1 return plaintext
def autokeyDecrypt(self, ciphertext, key): plaintext = '' numKey = [] self.generateLetterMatrix() ciphertext = cv.textToNum(ciphertext) numKey = cv.textToNum(key) counter = 0 for index in numKey: for letter in self.alphabet: if (ciphertext[counter] == self.alphabet.index( self.letter_matrix[self.alphabet.index(letter)][index]) ): plaintext += letter counter += 1 position = counter counter = 0 while (position < len(ciphertext)): for letter in self.alphabet: if (ciphertext[position] == self.alphabet.index( self.letter_matrix[self.alphabet.index(letter)][ self.alphabet.index(plaintext[counter])])): plaintext += letter position += 1 counter += 1 return plaintext
def encrypt(self, plaintext, key): ciphertext = '' numKey = [] self.generateLetterMatrix() plaintext = cv.textToNum(plaintext) numKey = cv.textToNum(key) counter = 0 for letter in plaintext: if (counter >= len(key)): counter = 0 ciphertext += self.letter_matrix[letter][numKey[counter]] counter += 1 return ciphertext
def encrypt(self, plaintext, key): ciphertext = [] plaintext = plaintext.lower() plaintext = cv.textToNum(plaintext) for letter in plaintext: ciphertext.append((letter + key) % 26) return cv.numToText(ciphertext)
def decrypt(self, ciphertext, key): plaintext = [] ciphertext = ciphertext.lower() ciphertext = cv.textToNum(ciphertext) for letter in ciphertext: plaintext.append((letter - key) % 26) return cv.numToText(plaintext)
def bruteForce(self, ciphertext): plaintext = [] buffer = [] ciphertext = cv.textToNum(ciphertext) for key in range(1,26): for letter in ciphertext: buffer.append((letter - key) % 26) plaintext.append(buffer) buffer = [] return cv.numArrayToText(plaintext)
def autokeyEncrypt(self, plaintext, key): ciphertext = '' numKey = [] self.generateLetterMatrix() plaintext = cv.textToNum(plaintext) numKey = cv.textToNum(key) counter = 0 for letter in numKey: ciphertext += self.letter_matrix[plaintext[counter]][letter] counter += 1 position = counter counter = 0 while (position < len(plaintext)): ciphertext += self.letter_matrix[plaintext[position]][ plaintext[counter]] counter += 1 position += 1 return ciphertext
def encrypt(self, plaintext): ciphertext = [] result = [] key = [] #pretvori tekst u polje brojeva u rasponu 0-25 plaintext = cv.textToNum(plaintext) #za svaku vrijednost otvorenog teksta dodaj pseudonasumican broj u rasponu 0-25 for value in range(len(plaintext)): key.append(rand.randrange(0, 26)) #modularno zborji otvoreni tekst i kljuc ciphertext = self.modularAddition(plaintext, key) ciphertext = cv.numToText(ciphertext) result.append(ciphertext) result.append(cv.numToText(key)) return result
def encrypt(self, plaintext, key, m=3): self.key = key ciphertext = '' letter_vector = [] buffer = [] #pretvori otvoreni tekst u niz brojeva plaintext = cv.textToNum(plaintext) plaintext = self.padPlaintext(plaintext, m) for value in plaintext: buffer.append(value) #Stvori 2D polje koje se sastoji od m-elementnih polja if (len(buffer) == m): letter_vector.append(buffer) buffer = [] ciphertext = self.calculateCipher(letter_vector, m) return ciphertext