CSCI XXXXXXXXXXLab #7 – Cryptography In this lab you will write three programs that implement various parts of the Caesar cipher. In this lab you will need to work with strings and input and output in...

I have 5 lab assignments that needs to be done for this beginners course


CSCI-101 Lab #7 – Cryptography In this lab you will write three programs that implement various parts of the Caesar cipher. In this lab you will need to work with strings and input and output in Python for the first time. To get you started, here are few simple Python programs that show the code that you will need to use to write the programs in this lab. You might want to copy these programs into PyCharm and experiment with them to make sure that you understand how they work. The following program reads in a first, then a last name, then prints the full name: first = input("Enter your first name: ") last = input("Enter your last name: ") print("Your full name is "+first+" "+last) This program reads in five numbers and prints the sum: sum = 0 for i in range(5): num = int(input("Enter a number: ")) sum = sum + num print("The sum is",sum) This program will read a string and then print out the characters that are not lowercase letters: lowerLetters = "abcdefghijklmnopqrstuvwxyz" message = input("Enter a string: ") for ch in message: if lowerLetters.find(ch)==-1: print(ch," is not a lowercase letter") This last program will read in a string and change any lowercase letters to uppercase. Note there is a much easier way to do this, but the program below will help you write the solutions to this lab. Note that letters that are not lower case, are simply copied (i.e., they are not converted): lowerLetters = "abcdefghijklmnopqrstuvwxyz" upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" message = input("Enter a string: ") output = "" for ch in message: pos = lowerLetters.find(ch) if pos==-1: output=output+ch else: output=output+upperLetters[pos] print(output) Activity 1: Write a program, named lab7-act1, that reads in a message and a key and produces as output the message encoded using a Caesar cipher using the given key. Assume that the message only contains lower case letters. Should a letter other than a lower-case letter should appear in the message, copy that character as is to the encrypted version of the message. A sample run of the program is shown below: Enter the message you wish to encrypt: I See 14 stars!! Enter the key (1-25): 6 I Skk 14 yzgxy!! Note that the “I”,”1”, “4”, “!”, and the spaces were just copied as is over to the encrypted version of the message. Activity 2: Write a program, named lab7-act2, that takes a message encrypted using a Caesar cipher and the key and prints the unencrypted message. As in the previous activity, assume that only lower-case letters need to be encrypted, anything else should just be copied over to the unencrypted message. A sample run of the program is shown below: Enter the message you wish to decrypt: I Skk 14 yzgxy!! Enter the key (1-25): 6 I See 14 stars!! Activity 3: Write a program, named lab7-act3, that takes a message encrypted and uses a brute force attack to decrypt the message. Your program should try all possible keys and print out the corresponding unencrypted. As in the previous activities, assume that only lower-case letters need to be encrypted, anything else should just be copied over to the unencrypted message. A sample run of the program is shown below: Enter the message you wish to decrypt: I Skk 14 yzgxy!! 0 - I Skk 14 yzgxy!! 1 - I Sjj 14 xyfwx!! 2 - I Sii 14 wxevw!! 3 - I Shh 14 vwduv!! 4 - I Sgg 14 uvctu!! 5 - I Sff 14 tubst!! 6 - I See 14 stars!! 7 - I Sdd 14 rszqr!! 8 - I Scc 14 qrypq!! 9 - I Sbb 14 pqxop!! 10 - I Saa 14 opwno!! 11 - I Szz 14 novmn!! 12 - I Syy 14 mnulm!! 13 - I Sxx 14 lmtkl!! 14 - I Sww 14 klsjk!! 15 - I Svv 14 jkrij!! 16 - I Suu 14 ijqhi!! 17 - I Stt 14 hipgh!! 18 - I Sss 14 ghofg!! 19 - I Srr 14 fgnef!! 20 - I Sqq 14 efmde!! 21 - I Spp 14 delcd!! 22 - I Soo 14 cdkbc!! 23 - I Snn 14 bcjab!! 24 - I Smm 14 abiza!! 25 - I Sll 14 zahyz!! cz sio wuh lyux nbcm, siol jlialug cm qilecha!!! CS-100 Lab 8 – Who is in the Building? After leaving GMU and getting dozens of job offers because you took CS-100, you decided to take a high paying job in NYC. The building you work in is secured in that you have a badge to enter the building. Each badge has a unique identifier that is recorded automatically by the security system when you pass through the doors of the building. Badges are read when an employee enters, or leaves the building, and the system only records the badge number. The scanner cannot determine whether the employee is entering or leaving the building, only that they passed through the scanner. Activity 1: Counting Lines (5 points) From the content section of the course web site (same place where you found this lab), download a copy of the file scanner_data.txt. Copy the folder in PyCharm where you will write the programs for this lab. Open the file in PyCharm. You will see that the file contains lines that look like this: f6967659-b6c6-4d91-82b7-71cf0ca3253a df16d777-c8c2-4fbb-8301-ababd84ffe0f 60acee8c-9d8c-4464-b9ab-69a5c5916da5 b625d35c-247f-4a5a-a377-c51f3a7461f2 … This file represents the data that is recorded by the security system in the building. Every time the system detects a badge, the badge number is recorded in the file. Note that badge may appear multiple times in the scanner file since the badges are detected whenever someone enters or leaves the building. Write a program, lab8_act1.py, that reads the scanner_data.txt file, line by line, and prints out the total number of lines contained in the file. Just so you know, there are a total of 441 lines in the file. Activity 2: Print Ids (10 points) In this activity you will write a program, lab8_act2.py, that will read the scanner data file and prints out the ids that appear in the file. Note that an id may appear multiple times in the scanner file but should only appear once in your output. Your program will also print out the number of ids found in the file. The output from your program should look something like this: f6967659-b6c6-4d91-82b7-71cf0ca3253a df16d777-c8c2-4fbb-8301-ababd84ffe0f 60acee8c-9d8c-4464-b9ab-69a5c5916da5 b625d35c-247f-4a5a-a377-c51f3a7461f2 …several lines of output omitted 7f4ec3cc-a8b7-4af0-883c-25bbff66f8c9 af130287-05d5-431d-9ab2-fb82b6a8c714 c739fb09-ab67-40f2-baa1-0d0d1564544c d74217de-1880-4a37-bfe8-54ee3e315b40 A total of 100 ids are the data file Think about how you would solve this problem by hand. You would probably get yourself a blank piece of paper and a pen. Then you would go through the scanner data file, line by line (badge by badge). For each badge, you would look on your piece of paper to see if it is there. If it is not there, you would write it down on the piece of paper. If the badge is on the piece of paper you would not write it down again, because you already saw it. After going through the badges in the file, the paper would contain a list of the badges that you saw. Now how would you do this in Python? We do not have pieces of paper in Python. I wonder how you might create a list of badges in Python. Activity 3: Who is in the building? (15 points) Your boss would like to know the ids of the people who are currently in the building. She would like you to write a program that reads the badge numbers recorded by the system and prints out the ids of the people who are currently in the building, followed by the count of the number of people who are in the building. Running your program on the scanner data should produce output similar to the following (note that several lines of output have been deleted to save trees): 78b3249f-4f3e-4685-8b8d-025373f4e164 5dbdc774-5df2-491b-b887-188c8f46e84c …39 lines of output omitted 7f4ec3cc-a8b7-4af0-883c-25bbff66f8c9 d74217de-1880-4a37-bfe8-54ee3e315b40 A total of 43 people are in the building Remember that the scanner only records when someone passes through the scanner and cannot determine if someone is entering or leaving the building. So, when a person enters the building their badge is scanned, and when they leave it is scanned again. Imagine that the security system maintains a list of the badges of the people currently in the building (this is separate from the data file). When a badge is detected entering or leaving the building, the system looks at this list. If the badge that was just detected, is not in the list, then the person with that badge must have entered the building (otherwise their badge would be in the list, right?) If the badge that was just detected is in the list, then the person with that badge must have left the building. Again, think about how you might solve this problem using a piece of paper. Initially there are no badges on the paper because the building starts out empty. When you are given a badge number, check the list on the paper. If the badge is not there, you know the person entered the building, and add it to the list on the paper. If the badge is in the list on the paper, the person left, so remove the badge from the list. If you think about this just a little bit, you will see this is very similar to what you did in the previous activity. Name your program lab8_act3.py. CS100 Lab 5
Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here