用Python代写加解密算法Dumbcrypt,一个类似Affine Cipher和Caesar Cipher的变种算法。Assignment Overview (learning objectives)This assignment will give you more experience on the use of:integers (int)conditionalsiterationstringThe goal of this project is to implement a different cryptographic technique by combining two cryptographic techniques. I call it dumbcrypt. Dumbcrypt is a combination of Affine Cipher and Caesar Cipher. The user will enter a sentence, a string composed of letters, numbers, and punctuation. Notice that spaces are not allowed in the input string because spaces provide too many clues to someone trying to crack your coded message. Your job is to encrypt the sentence using a combination of Affine and Caesar Cipher. The letters and numbers will be encrypted and decrypted using Affine Cipher; the punctuation using Caesar Cipher.Assignment BackgroundAffine Cipher - https://en.wikipedia.org/wiki/Affine\_cipherAffine Cipher is a bit different than Caesar Cipher in that the Affine Cipher uses an encryption function to calculate the integer that corresponds to the cipher text letter. The encryption function for a letter variable named x isE(x) = (Ax+N) mod M Where A and N are keys of the cipher and M is size of the alphabet (for example, M=26 for English letters; M = 36 for English letters plus digits). The decryption of Affine Cipher only works when A and M are co-primes of each other.N will be an input to the program and will be fixed for the whole run of the program. N is sometimes referred to as the “rotation” but is effectively a key.Co-primes are a pair of numbers whose greatest common divisor (GCD) is 1. Only one co-prime is needed (of possibly many). For this project we choose the smallest greater than one so everyone is using the same onemaking testing feasible.Algorithm:Calculate M, the number of characters in the alphabet (Hint: use len())Calculate A using get_smallest_co_prime(M)For the character to be encrypted find its index in the alphabet: x in the formula is the indexApply the formula to get the index of the cipher character: E(x) = (Ax+N) mod MUsing the index get the cipher character from the alphabetReturn the character.Decryption is a little more complicated than encryption. The decryption function isD(x) = A^-1(x-N) mod M Where A^-1 is the modular multiplicative inverse (https://en.wikipedia.org/wiki/Modular\_multiplicative\_inverse). We provide the function multiplicative_inverse(A,M) that calculates the multiplicative inverse, A^-1 , for you. The function checks all the numbers x from 1 to M and for every number x checks if (A*x) mod M is 1. Once you have the A^-1, you can use the decryption function to calculate the integer that corresponds to plaintext letter.The decryption algorithm is the same as encryption with two modifications:Algorithm:Calculate M, the number of characters in the alphabet (Hint: use len())Calculate A using get_smallest_co_prime(M)Calculate A-1 using the function multiplicative_inverse(A,M) .For the character to be encrypted find its index in the alphabet: x in the formula is the indexApply the formula to get the index of the cipher character: D(x) = A^-1(x-N) mod M Note the formula difference from encryption: the parentheses are different and it has subtraction.Using the index get the cipher character from the alphabetReturn the character.Caesar Cipher - https://en.wikipedia.org/wiki/Caesar\_cipherCaesar Cipher is a simplified form of Affine cipher which follows similar encryption and decryption algorithm. CaeSecurity代写:CSE231 Dumbcrypt代写Python实验sar Cipher uses a single key to calculate the integer that corresponds to the ciphertext letter. The encryption function isE(x) = (x+N) mod M The decryption function isD(x) = (x-N) mod M The algorithms for Caesar Cipher are similar to the Affine Cipher algorithmsProject DescriptionYour program must meet the following specifications:You have to use the eight functions in the provided proj04.py skeleton. You have to implement and use the following:a. check_co_prime(num, M): Takes two numbers as parameters. Returns True if num and M are co-primes, otherwise returns False. (Hint: used GCD)b. get_smallest_co_prime(M): Takes one number M as a parameter: Returns the smallest coprime of M that is greater than 1. For example, if M = 26, the smallest co- prime greater than one is 3. If M = 210, the smallest co-prime greater than one is 11. (Hint: use check_co_prime)c. caesar_cipher_encryption(ch,N,alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the cipher text character using the Caesar Cipher.d. caesar_cipher_decryption(ch,N, alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the plain text character using the Caesar Cipher.e. affine_cipher_encryption(ch,N, alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the cipher text character using the Affine Cipher.f. affine_cipher_decryption(ch,N,alphabet):Takesthreeinputs:a character to encrypt, the rotation N, and the alphabet. Returns the plain text character using the Affine Cipher.g. main(): Takes no input. Returns nothing. First prompts for rotation, N. Then prompts for a command (d,e,q), prompts for a string, decrypts or encrypts the string depending on the command using the encryption and decryption functions described above. Remember to use a different encryption/decryption algorithm for punctuation.Assignment DeliverableThe deliverable for this assignment is the following file:proj04.py - the source code for your Python program Be sure to use the specified file name and to submit it for grading via Mimir before the project deadline.Assignment Notes and Other RequirementsTo clarify the project specifications, sample output is appended to the end of this document.Convert all letters to lower case before encryption or decryption.Items 1-9 of the Coding Standard will be enforced for this project.We provide a proj04.py program for you to start with.You may import the GCD function from a module such as math.You are not allowed to use advanced data structures such as lists, sets, dictionaries and classes.You are not allowed to use the chr() function.There are two alphabets provided: numbers + letters and string.punctuationThe mod operator in the encryption formulas is the % operator in Python.The string method isalnum() returns True if the string is composed of letters and digits.The N in the formulas is often referred to as the “rotation” and is the first value prompted for. It effectively is the key for the encryption and decryption.Error checking (Hint: do error checking after everything else is working.)a. Re-prompt if the rotation is not an int.b. Print an error message and ignore any commands that are not ‘e’, ‘d’ or ‘q’.c. Print an error message if any of the text is not a letter, digit or punctuation. Note that a space will generate an error (spaces provide too many clues for cracking codes).A strings.txt file of strings used is provided to help with testing.I found else with the for statement to be useful to not print plain and cipher texts if there was an error with a character.转自:http://ass.3daixie.com/2019012256014380.html