Ask your own question, for FREE!
Computer Science 18 Online
EpicLeo:

Look at cipher.py, frequency.py, and letter_swapper.py. Describe three similarities and three differences in their code: # a212_cipher.py # Rotation Cipher # VARIABLES MAX_KEY_SIZE = 26 # FUNCTIONS def getMode(): while True: print('Do you wish to encrypt or decrypt a message?') mode = input().lower() if mode in 'encrypt e decrypt d brute b'.split(): return mode else: print('Enter either "encrypt" or "e" or "decrypt" or "d" or "brute" or "b".') def getMessage(): print('Enter your message:') return input() def getKey(): key = 0 while True: print('Enter the key number (1-%s)' % (MAX_KEY_SIZE)) key = int(input()) if (key >= 1 and key <= MAX_KEY_SIZE): return key def getTranslatedMessage(mode, message, key): if mode[0] == 'd': key = -key translated = '' for symbol in message: if symbol.isalpha(): num = ord(symbol) num += key if symbol.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif symbol.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 translated += chr(num) else: translated += symbol return translated # RUN THE PROGRAM mode = getMode() message = getMessage() if mode[0] != 'b': key = getKey() print('Your translated text is:') if mode[0] != 'b': print(getTranslatedMessage(mode, message, key)) else: for key in range(1, MAX_KEY_SIZE + 1): print(key, getTranslatedMessage('decrypt', message, key)) # a212_frequency.py # Counts letters in a given string # FUNCTIONS def char_frequency(str1): dict = {} for n in str1: keys = dict.keys() if n in keys: dict[n] += 1 else: dict[n] = 1 return dict # RUN THE PROGRAM phrase = input("Enter the string to analyze: ").upper() count_letters = char_frequency(phrase) letter_sort = sorted(count_letters.items(), key = lambda item: item[1], reverse=True) for letter in letter_sort: print (letter) # a212_letter_swapper.py # Implementation of RSA cryptography # using samples of large numbers # VARIABLES/INPUTS input_string = input("Enter the string to analyze: ").upper() solution = " "*len(input_string) # FUNCTIONS def results(): print("_"*50) for i in range(int(len(input_string)/50)+1): print("") print(solution[i*50:i*50+50])

Celestial:

@epicleo

Celestial:

Similarities: All three scripts involve user input to either encrypt/decrypt a message, analyze a string, or swap letters. They all define and use functions to perform specific tasks. The `char_frequency` function in `frequency.py`, the `getTranslatedMessage` function in `cipher.py`, and the `results` function in `letter_swapper.py`. They all have some form of output or display of results. Whether it's printing the frequency of letters in `frequency.py`, displaying the translated message in `cipher.py`, or printing the transformed string in blocks in `letter_swapper.py`. Differences: The purpose and functionality of each script differ. `cipher.py` focuses on encryption and decryption using a rotation cipher, `frequency.py` counts the frequency of letters in a string, and `letter_swapper.py` implements RSA cryptography using samples of large numbers. The input methods are different in each script. `cipher.py` and `letter_swapper.py` use the `input` function to get user input, while `frequency.py` takes the input as a command-line argument. The structure and organization of the code differ. `cipher.py` and `letter_swapper.py` both have a `RUN THE PROGRAM` section after defining functions, while `frequency.py` directly defines the function and then proceeds to the main program code. Also, `cipher.py` contains more user prompts and conditional statements compared to the other two scripts.

Celestial:

You're welcome

Celestial:

Also if you don't know in `cipher.py`, you can encrypt or decrypt a message using something called a rotation cipher.

Celestial:

It's like a secret code where you shift each letter in the message by a certain number. You get to choose that number, kind of like a secret key basically.

Celestial:

`frequency.py`, it's a bit different. You just give it a string, and it counts how often each letter appears in that string. It's like doing a tally of letters.

Celestial:

Kinda lame but used to analyze text if you're interested in that yk

Celestial:

Oh and the last one goes like hand-in-hand with cryptography, using RSA. It takes an input string from you, maybe a message or whatever you want to play with. Then, it does some intelligente calculations and swaps the letters around, like a secret code. The transformed string is stored in the solution classification yk that even prints out the transformed string in neat blocks of 50 characters. Why? I don't know, maybe just to be fancy or show off like yours truly 😏

Officialjennie:

despacito

curriful:

@officialjennie wrote:
despacito
.

toga:

Similarities: 1. All three programs accept user input as a string. 2. They all make use of functions to modularize the code. 3. They all have a section to run the program. Differences: 1. The first program uses a key to encrypt or decrypt a message, while the other two programs do not use a key. 2. The second program counts the frequency of letters in a given string, while the other programs encrypt or decrypt messages. 3. The third program implements RSA cryptography using samples of large numbers, while the other programs do not use this technique.

IceSpice:

@officialjennie wrote:
despacito
...

Bones:

@icespice wrote:
@officialjennie wrote:
despacito
...
Lol

ykbatman:

are you tryna hack the CIA?

ykbatman:

or tryna just unblock sum games

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!