2
$\begingroup$

If given a large set of examples of cyphertext and corresponding plaintext, could AI be trained to decrypt a cyphertext as the examples provided?, and if so, are there any examples online demonstrating this?

For example, lets imagine out cypher is a simple 7-shift ceaser shift, and we have a list of thousands of examples like so

olssv,hello 
ifl,bye
dvysk,world

Could a neural network be trained on these examples, and then shown a new cyphertext, not in the training set, such as "isbl" and correctly infer the result as "blue"?

$\endgroup$
3
$\begingroup$

Yes it could work for simple ciphers. Here's a quick example:

# dependencies
import numpy as np

# machine learning
from keras.models import Sequential
from keras.layers import Dense

# constants
BASE = 97
MAX = 26

# let's assign a = 1, z = 26, ciphertext x and decrypted value y
y = np.arange(0,MAX,1)
x = np.roll(y,-7)

model = Sequential()
model.add(Dense(256, input_dim=1, activation='relu'))
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(MAX, activation='softmax'))

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

history = model.fit(x, y, epochs = 500, verbose=0)

for x_test in [['o', 'l', 's', 's', 'v'], \
               ['i','f','l'], \
               ['d', 'v', 'y', 's', 'k']]:
  x_test = list(map(lambda x: ord(x) - BASE, x_test))
  # print (x_test)

  pred = model.predict_classes(x_test)
  print(list(map(lambda x: chr(x + BASE), pred)))

Predicted output: link here

['h', 'e', 'l', 'l', 'o'] ['b', 'y', 'e'] ['w', 'o', 'r', 'l', 'd']

$\endgroup$
3
$\begingroup$

That depends on the encryption. But for all simple monoalphabetic substitutions the answer is yes. And to don't need a neutral net, but the most simple classifier works. You train it on the letters of the cipher-texts, with the cleartext-letters being the classes. To apply the decryption to an unknown text, just let it classify each letter of the cipher independently and then concatenate the results to get the cleartext.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.