5740
Comment:
|
9230
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
This page was be created at Sage Days 103, 7-10 August 2019 by Sarah Arpin, Catalina Camacho-Navarro, Holly Paige Chaos, Amy Feaver, Eva Goedhart, Rebecca Lauren Miller, Alexis Newton, and Nandita Sahajpal. | This page was first created at Sage Days 103, 7-10 August 2019 by Sarah Arpin, Catalina Camacho-Navarro, Holly Paige Chaos, Amy Feaver, Eva Goedhart, Rebecca Lauren Miller, Alexis Newton, and Nandita Sahajpal. |
Line 7: | Line 7: |
We would also like to acknowledge Katherine Stange, who allowed us to use some of the code from her cryptography course as a starting point for many of these interacts. | We would also like to acknowledge Katherine Stange, who allowed us to use some of the code from her cryptography course as a starting point for many of these interacts. Dr. Stange's original code can be found at http://crypto.katestange.net/ |
Line 20: | Line 20: |
The shift cipher is a classical cryptosystem that takes plaintext and shifts it through the alphabet by a given number of letters. -EG | The shift cipher is a classical cryptosystem that takes plaintext and shifts it through the alphabet by a given number of letters. -EG For example, a shift of 2 would replace all A's with C's, all B's with D's, etc. When you reach the end of the alphabet, the letters are shifted cyclically back to the beginning. Thus, a shift of 2 would replace Y's with A's and Z's with B's. -AF |
Line 63: | Line 65: |
An affine cipher combines the idea of a shift cipher with a multiplicative cipher. In this particular example, we map consecutive letters of the alphabet to consecutive numbers, starting with A=0 (you can also do this cipher differently, and starting with A=1). The user selects two values, a and b. The value a is the multiplier and must be relatively prime to 26 in order to guarantee that each letter is encoded uniquely. The value b is the addend. Each letter's value is multiplied by a, and the product is added to b. This is then replaced with a new letter, corresponding to the result modulo 26. -AF | |
Line 67: | Line 70: |
print "Notice that the only choices for a can be numbers that are relatively prime to 26" | |
Line 69: | Line 73: |
def affine_cipher(message = input_box(default='"secrets"', width = 50), a=[1,3,4..12,14,15..25], b =[0..25]): | def affine_cipher(message = input_box(default='"secrets"', width = 50), a=[1,3,5,7,9,11,15,17,19,21,23], b =[0..25]): |
Line 92: | Line 96: |
== Frequency Analysis Tools == Frequency analysis is a technique for breaking a substitution cipher that is based on the frequencies that letters appear (in large chunks of text) in the English language. For example, E is the most common letter in the English language, so if a piece of encrypted text had many instances of the letter Q, you would guess that Q had been substituted in for E. === Letter Frequency Counter === by Rebecca Lauren Miller, Katherine Stange #Text From Amy Feaver. |
|
Line 93: | Line 108: |
#Last Edited 8/8/19 at 2:36pm print "This interact prints a bar graph of the distribution of the letters in the input text. Warning: the smaller the input text the less accurate the distribution will be. Letters that do not occur will not appear in the graph." # Initial text is "Greetiiiings my name is Weeegbert Deuce the True Eater of the Toupee. Hear ye, hear ye! Dee dee dee. A head of these liger cubs carrying the trippy tomahawks are coming fo' thee. Take shelters in the tombs. Tammy ran to the other townspeople and aardvarks. What is her ETA? Her ETA please! Toil, bring your food cups and oil and be swift. The women and the child Occotion CIII should pick bamboo at Atitisoting. See? Nanna Wu Shacah's inner noodle cups: not nuutty sesame notions." @interact def frequencyAnalysis(text = input_box('"Nyllappppunz tf uhtl pz Dlllnilya Klbjl aol Aybl Lhaly vm aol Avbwll. Olhy fl, olhy fl! Kll kll kll. H olhk vm aolzl spnly jbiz jhyyfpun aol aypwwf avthohdrz hyl jvtpun mv aoll. Ahrl zolsalyz pu aol avtiz. Ahttf yhu av aol vaoly avduzwlvwsl huk hhykchyrz. Doha pz oly LAH? Oly LAH wslhzl! Avps, iypun fvby mvvk jbwz huk vps huk il zdpma. Aol dvtlu huk aol jopsk Vjjvapvu JPPP zovbsk wpjr ihtivv ha Hapapzvapun. Zll.Uhuuh Db Zohjho z puuly uvvksl jbwz: uva ubbaaf zlzhtl uvapvuz."', width = 150)): alphabet = AlphabeticStrings() englishText = alphabet.encoding(text) distribution = englishText.frequency_distribution() L1 = englishText.frequency_distribution().function() L1=[x for x in L1.items()] L1.sort(key=lambda x:x[0]) labels, ys = zip(*L1) import numpy as np import math from matplotlib import pyplot as plt xs = np.arange(len(labels)) plt.bar(xs, ys, align='center') plt.xticks(xs, labels) #Replace default x-ticks with xs, then replace xs with labels plt.ylim(0,.2) plt.yticks(ys) plt.xlabel('Letters (Some may be missing)') plt.ylabel('Frequency') plt.show() |
|
Line 95: | Line 135: |
== Frequency Analysis Decryption Tool == |
|
Line 103: | Line 141: |
by Holly Paige Chaos, Rebecca Lauren Miller, and Kate Stange | by Holly Paige Chaos, Rebecca Lauren Miller, Katherine Stange |
Line 110: | Line 148: |
#This encrypts your message: Final 8/7/19. Written by Rebecca Lauren Miller, Holly Paige Chaos, Kate Strange. | #This encrypts your message: Final 8/7/19. Written by Rebecca Lauren Miller, Holly Paige Chaos, Katherine Stange. |
Line 126: | Line 164: |
#This decrypts your message: Final 8/7/19. Written by Rebecca Lauren Miller, Holly Paige Chaos, Kate Strange. | #This decrypts your message: Final 8/7/19. Written by Rebecca Lauren Miller, Holly Paige Chaos, Katherine Stange. |
Line 140: | Line 178: |
by Holly Paige Chaos and Rebecca Lauren Miller | by Holly Paige Chaos, Rebecca Lauren Miller |
Sage Interactions - Cryptography - Under Construction
This page was first created at Sage Days 103, 7-10 August 2019 by Sarah Arpin, Catalina Camacho-Navarro, Holly Paige Chaos, Amy Feaver, Eva Goedhart, Rebecca Lauren Miller, Alexis Newton, and Nandita Sahajpal.
We would also like to acknowledge Katherine Stange, who allowed us to use some of the code from her cryptography course as a starting point for many of these interacts. Dr. Stange's original code can be found at http://crypto.katestange.net/
If you have cryptography-related interactions that you are interested in adding to this page, please do so. You can also contact Amy Feaver at [email protected]
goto interact main page
Shift Cipher
by Sarah Arpin, Alexis Newton
The shift cipher is a classical cryptosystem that takes plaintext and shifts it through the alphabet by a given number of letters. -EG
For example, a shift of 2 would replace all A's with C's, all B's with D's, etc. When you reach the end of the alphabet, the letters are shifted cyclically back to the beginning. Thus, a shift of 2 would replace Y's with A's and Z's with B's. -AF
Shift Cipher Encryption
Shift Cipher Decryption
If you know that your message was encrypted using a shift cipher, you can use the known shift value to decrypt. If this is not known, brute force can be used to get 26 possible decrypted messages.
Affine Cipher
by Sarah Arpin, Alexis Newton
An affine cipher combines the idea of a shift cipher with a multiplicative cipher. In this particular example, we map consecutive letters of the alphabet to consecutive numbers, starting with A=0 (you can also do this cipher differently, and starting with A=1). The user selects two values, a and b. The value a is the multiplier and must be relatively prime to 26 in order to guarantee that each letter is encoded uniquely. The value b is the addend. Each letter's value is multiplied by a, and the product is added to b. This is then replaced with a new letter, corresponding to the result modulo 26. -AF
Substitution Cipher
by Catalina Camacho-Navarro
A simple cipher to encrypt messages in which each letter is assigned to another letter. Brute force or frequency analysis can be used to decrypt. -EG
Playfair Cipher
A special type of substitution cipher in which the plaintext is broken up into two-letter digraphs with some restrictions. Those digraphs are encrypted using a Polybius square, (i.e. a 5x5 grid in which each letter of the alphabet is its own entry with the exception of ij which are placed together). The positions of the letters in the digraph determine how the digraph is encrypted.
Frequency Analysis Tools
Frequency analysis is a technique for breaking a substitution cipher that is based on the frequencies that letters appear (in large chunks of text) in the English language. For example, E is the most common letter in the English language, so if a piece of encrypted text had many instances of the letter Q, you would guess that Q had been substituted in for E.
Letter Frequency Counter
by Rebecca Lauren Miller, Katherine Stange
#Text From Amy Feaver.
Vigenère Cipher
by Holly Paige Chaos, Rebecca Lauren Miller, Katherine Stange
Using a secret code word, encrypt each letter by shifting it the corresponding letter in the code word. -EG
Vigenère Cipher Encryption
Vigenère Cipher Decryption
Hill Cipher
by Holly Paige Chaos, Rebecca Lauren Miller
RSA
Named for the authors Rivest, Shamir, Aldeman, RSA uses exponentiation and modular arithmetic to encrypt and decrypt messages between two parties. Each of those parties has their own secret and public key. To see how it works, following along while Alicia and Bernadette share a message. -EG
Diffe-Hellman Key Exchange