From dfb50ddd2828e351476184e9cd318e6046ba3ee1 Mon Sep 17 00:00:00 2001 From: Nora Moor <135470174+noramoor2007@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:32:13 -0500 Subject: [PATCH] Edits --- C13Extension.html | 14548 +++++++++++++++++++++++++++++++++++++++ C13GroupWork.html | 15086 +++++++++++++++++++++++++++++++++++++++++ C13LectureNotes.html | 14538 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44172 insertions(+) create mode 100644 C13Extension.html create mode 100644 C13GroupWork.html create mode 100644 C13LectureNotes.html diff --git a/C13Extension.html b/C13Extension.html new file mode 100644 index 0000000..1f983c7 --- /dev/null +++ b/C13Extension.html @@ -0,0 +1,14548 @@ + + +
+ + +import pandas as pd
+
url = "https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/recent-grads.csv"
+
df = pd.read_csv(url)
+
type(pd)
+
module+
df.head()
+
+ | Rank | +Major_code | +Major | +Total | +Men | +Women | +Major_category | +ShareWomen | +Sample_size | +Employed | +... | +Part_time | +Full_time_year_round | +Unemployed | +Unemployment_rate | +Median | +P25th | +P75th | +College_jobs | +Non_college_jobs | +Low_wage_jobs | +
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | +1 | +2419 | +PETROLEUM ENGINEERING | +2339.0 | +2057.0 | +282.0 | +Engineering | +0.120564 | +36 | +1976 | +... | +270 | +1207 | +37 | +0.018381 | +110000 | +95000 | +125000 | +1534 | +364 | +193 | +
1 | +2 | +2416 | +MINING AND MINERAL ENGINEERING | +756.0 | +679.0 | +77.0 | +Engineering | +0.101852 | +7 | +640 | +... | +170 | +388 | +85 | +0.117241 | +75000 | +55000 | +90000 | +350 | +257 | +50 | +
2 | +3 | +2415 | +METALLURGICAL ENGINEERING | +856.0 | +725.0 | +131.0 | +Engineering | +0.153037 | +3 | +648 | +... | +133 | +340 | +16 | +0.024096 | +73000 | +50000 | +105000 | +456 | +176 | +0 | +
3 | +4 | +2417 | +NAVAL ARCHITECTURE AND MARINE ENGINEERING | +1258.0 | +1123.0 | +135.0 | +Engineering | +0.107313 | +16 | +758 | +... | +150 | +692 | +40 | +0.050125 | +70000 | +43000 | +80000 | +529 | +102 | +0 | +
4 | +5 | +2405 | +CHEMICAL ENGINEERING | +32260.0 | +21239.0 | +11021.0 | +Engineering | +0.341631 | +289 | +25694 | +... | +5180 | +16697 | +1672 | +0.061098 | +65000 | +50000 | +75000 | +18314 | +4440 | +972 | +
5 rows × 21 columns
+# Problem 1
+# XOR(): Takes as input two binary integers (or binary strings of length 1) and outputs the exclusive or
+# of those values according to the exclusive or table shown in class.
+
+x = int(input("Input a value for x (either 1 or 0): "))
+y = int(input("Input a value for y (either 1 or 0): "))
+def XOR(x, y):
+ if (x == 0 and y == 0):
+ xor = 0
+ if (x == 1 and y == 1):
+ xor = 0
+ if ((x == 1 and y == 0) or (x == 0 and y == 1)):
+ xor = 1
+ print("The exclusive of x and y is", xor)
+XOR(x, y)
+
Input a value for x (either 1 or 0): 0 +Input a value for y (either 1 or 0): 1 +The exclusive of x and y is 1 ++
# Problem 2
+# convertStringToBinary(): Takes as input a string and outputs a binary string. The function should
+# convert each character to it’s ascii value and then use the binary representation of that ascii value as
+# the binary representation of the character. The output string should be the binary representation of
+# each character in the input string, contained in a single string without spaces or special characters.
+
+def convertStringToBinary(char):
+ char = input("Input a string: ")
+ asciichar = ord(char)
+ bitstring = format(asciichar, "b")
+ print(bitstring)
+convertStringToBinary(char)
+
Input a string: d +1100100 ++
# Binary string to decimal integer
+binarystring = "100"
+integer = int(binarystring, 2)
+print(type(integer))
+print(integer)
+
<class 'int'> +4 ++
# Decimal integer to binary string
+integer = 65
+bitstring = format(integer, "b")
+print(type(bitstring))
+print(bitstring)
+
<class 'str'> +1000001 ++
def convertStringToBinary(char):
+ asciichar = ord(char)
+ bitstring = format(asciichar, "b")
+ print(bitstring)
+char = input("Input a string: ")
+convertStringToBinary(char)
+
Input a string: ! +100001 ++
# Problem 3
+# convertBinaryToString(): Reverses the previous function. Takes as input a binary string. The
+# function should convert each group of seven bits to the decimal representation of that number, which
+# is the ascii value of a character. Then the function should convert that ascii value back to an alphabetic
+# character and return the string of alphabetic characters.
+
+# Binary string to decimal integer
+def convertBinaryToString(binarystring):
+ integer = int(binarystring, 10)
+ print(type(integer))
+ # print(integer)
+ asciichar = ord(binarystring)
+ bitstring = format(asciichar, "b")
+ print(bitstring)
+ print(binarystring)
+ asciichar = chr(asciichar)
+ return asciichar
+binarystring = input("Input a binary string: ")
+convertBinaryToString(binarystring)
+
Input a binary string: 1 +<class 'int'> +110001 +1 ++
'1'+
# Problem 1
+# OTPkeyGen(): The function should take as input an integer indicating the length of the string to be
+# returned. The function should compute a random binary string of the required length and return that
+# string. You should use the random module here.
+
+import random
+def OTPkeyGen(num):
+ key = []
+ for i in range(num):
+ key.append(random.randint(0,1))
+ return key
+num = int(input("Input an integer for the length of the string: "))
+OTPkeyGen(num)
+
Input an integer for the length of the string: 8 ++
[0, 0, 1, 1, 0, 0, 1, 0]+
string = str("")
+def OTPkeyGen(lengthofstring):
+ print(type(string))
+ integer
+integer = len(string)
+lengthofstring = int(input("Input an integer: "))
+OTPkeyGen(integer)
+
Input an integer: 5 +<class 'str'> ++
def OTPkeyGen(lengthofstring):
+ print(type(lengthofstring))
+ string1 = ""
+ random = (0, lengthofstring)
+ string1 = random.randint(0, lengthofstring)
+ #for random in range(0, lengthofstring, random):
+ str = lengthofstring * random
+ print(string1 * random)
+ return string1
+lengthofstring = int(input("Input a length of a string: "))
+OTPkeyGen(lengthofstring)
+
Input a length of a string: 44 +<class 'int'> ++
+--------------------------------------------------------------------------- +AttributeError Traceback (most recent call last) +<ipython-input-33-102d717e2523> in <module> + 9 return string1 + 10 lengthofstring = int(input("Input a length of a string: ")) +---> 11 OTPkeyGen(lengthofstring) + +<ipython-input-33-102d717e2523> in OTPkeyGen(lengthofstring) + 3 string1 = "" + 4 random = (0, lengthofstring) +----> 5 string1 = random.randint(0, lengthofstring) + 6 #for random in range(0, lengthofstring, random): + 7 str = lengthofstring * random + +AttributeError: 'tuple' object has no attribute 'randint'+
import random
+def OTPkeyGen(num):
+ key = []
+ for i in range(num):
+ key.append(random.randint(0,1))
+ return key
+num = int(input("Input an integer for the length of the string: "))
+OTPkeyGen(num)
+
# Problem 2
+# OTPEncrypt(): The function should take as input the secret key (as a binary string) and a message
+# (as an alphabetic string) and output the binary string ciphertext. The function should first convert
+# the message to binary, using the convertStringToBinary() function above. Then the function should
+# compute the exclusive or of the message, bit by bit, with the key using the XOR() function above. The
+# function should return a binary string which is the ciphertext. If the secret key is shorter than the
+# message in binary, the function should return False.
+
+def OTPEncrypt(message):
+ secretmessage = ""
+ asciimessage = chr(message)
+ bitstring = format(asciimessage, secretmessage)
+ print(bitstring)
+ #message = secretkey.isalpha()
+ #binarystringctxt
+message = int(input("Input a message: "))
+OTPEncrypt(message)
+
Input a message: Hello! ++
+--------------------------------------------------------------------------- +ValueError Traceback (most recent call last) +<ipython-input-36-c98434934bd4> in <module> + 14 #message = secretkey.isalpha() + 15 #binarystringctxt +---> 16 message = int(input("Input a message: ")) + 17 OTPEncrypt(message) + +ValueError: invalid literal for int() with base 10: 'Hello!'+
# OTP encrypt function
+# Definition header
+def OTPEncrypt(sk, msg): # takes secret key and message as input
+ # convert message to binary using the convert string to binary function
+ # the binary message will be called binmsg
+ # iterate through the binmsg, which will be all 0, 1
+ # for loop or while loop through binmsg and key at the same time
+ # compute the xor of binmsgchar and key
+ # take output bit and concatonate to another string called ciphertext
+# example
+key = 0 1 1 0 1
+msg = 1 1 0 0 0
+
+ctxt = 1 0 1 0 1
+
+# doo something like this
+ctxt[i] == XOR(key[i], msg[i])
+
+ File "<ipython-input-37-2d50b1b0e4f2>", line 11 + key = 0 1 1 0 1 + ^ +IndentationError: expected an indented block ++
def otpencrypt(sk, msg):
+
+ File "<ipython-input-38-75829cd4b250>", line 1 + def otpencrypt(sk, msg): + ^ +SyntaxError: unexpected EOF while parsing ++
# Definition Header
+def OTPEncrypt(sk, msg): # Takes secret key and message as input.
+ #msg = input("Enter a secret message: ")
+ #sk = int(0, 1)
+ print(msg)
+ print(len(msg) * sk)
+ sk = len(msg)
+msg = input("Enter a secret message: ")
+sk = random.randint(0, 1)
+
+OTPEncrypt(sk, msg)
+ # Convert message to binary using the "convertStringToBinary():" function.
+ # The binary message will be called "binmsg" in this code.
+ # Iterate through the "binmsg", which will be all 01.
+ # Use a for or a while loop through "binmsg" and key at the same time.
+ # Compute the XOR() of "binmsgchar" and "key" in the function.
+ # Take output bit and concatonate to another string called "ciphertext"
+
Enter a secret message: hello! +hello! +6 ++
ctxt[i] == XOR(key[i], msg[i])
+ +import random
+# Definition Header
+def OTPEncrypt(sk, msg): # Takes secret key and message as input.
+ #msg = input("Enter a secret message: ")
+ #sk = int(0, 1)
+ print(msg)
+ print(len(msg) * sk)
+ sk = len(msg)
+msg = input("Enter a secret message: ")
+sk = random.randint(0, 1)
+OTPEncrypt(sk, msg)
+ # Convert message to binary using the "convertStringToBinary():" function.
+ # The binary message will be called "binmsg" in this code.
+ # Iterate through the "binmsg", which will be all 01.
+ # Use a for or a while loop through "binmsg" and key at the same time.
+ # Compute the XOR() of "binmsgchar" and "key" in the function.
+ # Take output bit and concatonate to another string called "ciphertext"
+
Enter a secret message: The passcode is 13524323. +The passcode is 13524323. +25 ++
# Problem 1
+# The function should take as input the string that you intend to encrypt andreturn the length
+# of the secret key required to encrypt that string.
+
+def problem1(string):
+ return len
+string = input("Enter a set characters: ")
+problem1(string)
+
Enter a set characters: shdfsa ++
<function len(obj, /)>+
def CaesarEncrypt(key, message): #encryption function # key is an integer message is a string
+ ciphertext = ""
+ message = message.upper()
+ for char in message:
+ if (char.isalpha()):
+ asciichar = ord(char)
+ asciichar += key
+ if asciichar > 90:
+ asciichar -= 26
+
+ newchar = chr(asciichar)
+ else:
+ newchar = char
+ ciphertext += newchar
+
+ return ciphertext
+ciphertext = CaesarEncrypt(2, "xyz!")
+print(ciphertext)
+ # use ord and chr to switch back and forth
+ # shift it forward
+ #go through each character inthe message
+ # convert to ascii
+ # shift it by the key value
+ #Append to some string
+
ZAB! ++
sk = 2
+msg = ("xyz!")
+ciphertext = CaesarEncrypt(sk, msg)
+print(ciphertext)
+
ZAB! ++
def CaesarDecrypt(key, ciphertext): #decryption function # key is an integer ciphertext is a string
+ #shift it back
+ message = ""
+ ciphertext = ciphertext.upper()
+ for char in ciphertext:
+ if (char.isalpha()):
+ asciichar = ord(char)
+ asciichar -= key
+ if asciichar < 65:
+ asciichar += 26
+
+ newchar = chr(asciichar)
+ else:
+ newchar = char
+ message += newchar
+
+ return message
+
import random
+def CaesarKeyGen():
+ return random.randint(1, 25)
+
sk = 2
+msg = ("xyz!")
+ciphertext = CaesarEncrypt(sk, msg)
+print(ciphertext)
+decmessage = CaesarDecrypt(sk, ciphertext)
+print(decmessage)
+
ZAB! +XYZ! ++
sk = CaesarKeyGen()
+print("The secret key is now:", sk)
+msg = input("Enter a secret message: ")
+print("The message is: ", msg)
+ctxt = CaesarEncrypt(sk, msg)
+print("The ciphertext is: ", ctxt)
+decryptedMsg = CaesarDecrypt(sk, ctxt)
+print("The decrypted message is: ", decryptedMsg)
+if(msg.upper() == decryptedMsg):
+ print("Success")
+else:
+ print("Looks like something went wrong.")
+
The secret key is now: 19 +Enter a secret message: The password to my computer is 135regqfq3wr. +The message is: The password to my computer is 135regqfq3wr. +The ciphertext is: MAX ITLLPHKW MH FR VHFINMXK BL 135KXZJYJ3PK. +The decrypted message is: THE PASSWORD TO MY COMPUTER IS 135REGQFQ3WR. +Success ++
def substitutionkeygen():
+ print("test")
+def substitutionencrypt(sk, msg):
+ print("test")
+def substitutiondecrypt(sk, ctxt):
+ print("test")
+
def getFreq(ctxt):
+ print("test")
+def guessSK(freqdictionary, mode):
+ print("test")
+