This notebook shows a method for encrypting and decrypting stings based on the Playfair cypher. Specifically, this cypher uses a password that is time-dependent, so the time of encryption must be near the time of decryption.
The following modules are imported for a Python implementation.
original
is a string consisting of the 81 characters allowed to be used in the serial to be encrypted.
make_enc_grid()
takes a string ticket
and forms a string with an encoding of the current date and time, followed by the characters in ticket, followed by the characters in original
. Then, only the first occurance of each character in original
is added to an array (so the array is always exactly 81 characters). The array is reshaped to be 9-by-9 and is returned. This original (and time-dependent) arrangement of the 81 original characters will be used for the encryption and decryption.
plyf_encrypt()
uses the playfair algorythm to encrypt serial
with the grid, make_encr_grid(ticket)
.
Similarly, plyf_decrypt
decrypts an encoded message using make_encr_grid(ticket)
.
Since the password for the encryption and decryption is time-dependent, it is important to make sure that on average, the encryption and decryption process does not get separated by the time-accuracy difference. That is, the encryption and decryption must be fast enough so the time does not change between encryption and decryption. The following script shows the percent of encryptions/decryptions that do not get disturbed by a change in time.
The following script demosntrates how this method works.
The following script shows how the devolution of decryptions progresses over time.
As can be seen from the sparce occurance of the original serial being decrypted, it is still possible (although seemingly unlikely) that the decryption will yield the original serial. The longer the initial serial is, the less likely that this will happen. The script below counts when the delayed decryption matches the original but this time uses a randomly generated serial of length 500.
If more security is wanted, time_dep_serial
creates a serial number that expires with respect to time, as checked by check_time_dep_serial
.