Compare commits
19 Commits
main
...
Encrypted-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ab8061323 | ||
|
|
f2505c6994 | ||
|
|
a2844c1359 | ||
|
|
a45e81e900 | ||
|
|
e1ebaa5dd4 | ||
|
|
e5f8d22e78 | ||
|
|
24d1cdca55 | ||
|
|
129429b48b | ||
|
|
1ade3555f0 | ||
|
|
251e78e3fd | ||
|
|
33e267901e | ||
|
|
1e16e3ef1b | ||
|
|
091ad5995b | ||
|
|
072a435416 | ||
|
|
e878c3ae73 | ||
|
|
f13ece0241 | ||
|
|
8666543b1f | ||
|
|
0a3a17cc1f | ||
|
|
d874c43814 |
@@ -11,11 +11,11 @@
|
||||
#
|
||||
# @Script: CutieDecrypt.py
|
||||
# @Date Created: 10 Apr, 2024
|
||||
# @Last Modified: 13 Apr, 2024
|
||||
# @Last Modified: 15 Apr, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
# ----------------------------------------------------------
|
||||
|
||||
def decrypt(dataEncoded: str, keyDecrypt: str, keyEnglish: str):
|
||||
def decrypt(dataEncoded: str, keyDecrypt: str, keyLanguage: str="EATBISNPHRLQYCDUOMVWKFXGZJ".upper()):
|
||||
"""
|
||||
Decrypts a string encoded using a substitution cypher based on the provided key.\n
|
||||
Characters closer to index 0 in `key` are more common in the English language.
|
||||
@@ -23,26 +23,23 @@ def decrypt(dataEncoded: str, keyDecrypt: str, keyEnglish: str):
|
||||
|
||||
dataDecrypted = ""
|
||||
|
||||
for c in dataEncoded:
|
||||
for c in dataEncoded: # Decrypt each character.
|
||||
is_found = False
|
||||
|
||||
if c != " ":
|
||||
if c in keyDecrypt: # Attempt to decrypt each character.
|
||||
while not is_found:
|
||||
for k in keyDecrypt:
|
||||
if c == k: # Character found in decryption key.
|
||||
dataDecrypted = dataDecrypted + keyEnglish[keyDecrypt.index(k)]
|
||||
dataDecrypted = dataDecrypted + keyLanguage[keyDecrypt.index(k)]
|
||||
is_found = True
|
||||
else:
|
||||
else: # Failed to decrypt a character, passing and leaving character as is.
|
||||
dataDecrypted = dataDecrypted + c
|
||||
|
||||
return dataDecrypted
|
||||
|
||||
with open("dataEncoded19.ENC", "r") as f:
|
||||
data = "".join(c for c in f.read() if c != "\n")
|
||||
with open("/mnt/EnderChest/beartech/Workspace/CutieDecryptor/dataEncoded19.ENC", "r") as f:
|
||||
data = f.read()
|
||||
|
||||
with open("key.txt", "r") as f:
|
||||
key = "".join(c for c in f.read() if c != "\n")
|
||||
|
||||
key = "qwertyuiopasdfghjklzxcvbnm" # Temporary - Faux testing key.
|
||||
english = "etaoinshrdlcumwfgypbvkjxqz" # Temporary - Lewand's order of english characters; most to least common.
|
||||
|
||||
print(decrypt(data, key, english))
|
||||
print(decrypt(data,
|
||||
"BWIAFYPMRNZQCXKJLGTVHOSEUD",
|
||||
"EATSINORHLCDMUPFYGWBVKXJZQ"))
|
||||
@@ -11,8 +11,8 @@
|
||||
#
|
||||
# @Script: CutieParser.py
|
||||
# @Date Created: 10 Apr, 2024
|
||||
# @Last Modified: 11 Apr, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
# @Last Modified: 29 Apr, 2024
|
||||
# @Last Modified by: JellieJayde | Jayde Paquette
|
||||
|
||||
# ----------------------------------------------------------
|
||||
#
|
||||
@@ -20,7 +20,68 @@
|
||||
#
|
||||
# ----------------------------------------------------------
|
||||
|
||||
with open("dataReference.txt", "r") as f:
|
||||
data = f.read()
|
||||
from os import path
|
||||
|
||||
":"
|
||||
execDir = path.dirname(__file__)
|
||||
|
||||
def order(file): # This is the main function that we will use to decrypt the code
|
||||
|
||||
dataLanguage = [] # Variables:
|
||||
amount = [] # -
|
||||
index = 0 # -
|
||||
sortedString = "" # -
|
||||
|
||||
with open(execDir + file, "r") as f: # With the readable file:
|
||||
# -------------------------------------------------------------------------------------------------------
|
||||
while True: # Will loop from this line ^ to the next one, until told otherwise
|
||||
fileChar = f.read(1).strip() # Reads the first character in the file
|
||||
|
||||
if fileChar.isalpha(): # If the character is in the alphabet (aka. a, b, c, etc...):
|
||||
if fileChar.upper() not in dataLanguage: # If the character is not in the (currently) empty list:
|
||||
dataLanguage.append(fileChar.upper()) # Put the character in the empty list
|
||||
amount.append(1) # Gives that letter an amount of 1, with the same index
|
||||
|
||||
else: # If the charatcer is in the alphabet, but is already in the list, then:
|
||||
index = 0 # Set the "index" variable to 0
|
||||
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
while True: # Loop from this ^ line to the next until told otherwise
|
||||
if dataLanguage[index] == fileChar.upper(): # If the letter with the index (which is currently zero) is the same as the current character:
|
||||
amount[index] = amount[index] + 1 # Add one to the amount of that charcater
|
||||
break # Break the loop
|
||||
|
||||
else: # If the letter isn't the same as the current character:
|
||||
index = index + 1 # Add one to the index variable, then continue the loop
|
||||
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
if fileChar == "~": # If the character is a tilde (I put a tilde at the end of the file so the program knows when the file is finished)
|
||||
index = 0 # The index variable is now 0
|
||||
Finished = False # Add a "Finished" variable
|
||||
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
while not Finished: # If the "Finished" variable is false, it will loop from this line ^ to the next, until told other wise
|
||||
Finished = True # Set's finished to true, but wont stop the loop because it just started the first cycle
|
||||
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
for index in range(0, len(amount) - 1): # Will loop from this line ^ to the next for how many items are in the "amount" list
|
||||
temp = amount[index] # Make a new variable, "temp" into a number in the amount list
|
||||
tempLetter = dataLanguage[index] # Do the same thing, but with "tempLetter", and instead of a number, it's a ltter
|
||||
|
||||
if temp < amount[index + 1]: # If the temperaroy number is less than the amount declared:
|
||||
amount[index] = amount[index + 1] # it will the replace the number declared in the "amount" list with the number ahead of it
|
||||
amount[index + 1] = temp # Will replace the number ahead of the amount declared, with the temperaroy number
|
||||
|
||||
dataLanguage[index] = dataLanguage[index + 1] # Replace the letter associated with the same index with the one ahead of it
|
||||
dataLanguage[index + 1] = tempLetter # Replace the letter ahead with the temperary letter
|
||||
|
||||
Finished = False # Make the "Finsihed" variable false, therefore resarting the loop
|
||||
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
if index == len(amount): # If the index is equal to the amount of numbers in the "amount" string
|
||||
index = 0 # Reset the index
|
||||
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
for i in dataLanguage: # Will loop this next line for how many letters are in the "dataLanguage" list
|
||||
sortedString = sortedString + i # Add the letter it reads into a string
|
||||
|
||||
|
||||
return sortedString # Returns the string
|
||||
# ------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# Then shows the data, proving it works
|
||||
print (order("\\dataReference.txt"), "\n")
|
||||
print (order("\\dataEncoded19.ENC"), "\n")
|
||||
71
OliviaParse.py
Normal file
71
OliviaParse.py
Normal file
@@ -0,0 +1,71 @@
|
||||
#!~/.pyenv/versions/3.11.6/bin/python
|
||||
#
|
||||
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||
#
|
||||
# -*- coding:utf-8 -*-
|
||||
# @Title: OliviaParser
|
||||
# @Author: Cutieguwu | Olivia Brooks
|
||||
# @Collaborator: JellieJayde | Jayde Paquette
|
||||
# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca
|
||||
# @Description: Parses an encrypted and unencrypted file to discern a decryption key.
|
||||
#
|
||||
# @Script: CutieDecrypt.py
|
||||
# @Date Created: 22 Apr, 2024
|
||||
# @Last Modified: 28 Apr, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
# ----------------------------------------------------------
|
||||
|
||||
# Fetch English language reference text and encoded text.
|
||||
with open("/mnt/EnderChest/beartech/Workspace/CutieDecryptor/dataReference.txt", "r") as f:
|
||||
dataReference = f.read()
|
||||
|
||||
with open("/mnt/EnderChest/beartech/Workspace/CutieDecryptor/dataEncoded19.ENC", "r") as f:
|
||||
dataEncoded = f.read()
|
||||
|
||||
def parse(data):
|
||||
"""
|
||||
Parses a string and orders the characters present within from most to least frequent.
|
||||
"""
|
||||
|
||||
characters = {}
|
||||
|
||||
for character in data:
|
||||
character = character.upper()
|
||||
if character.isalpha():
|
||||
try:
|
||||
characters[character] = characters[character] + 1 # Increment the character frequency.
|
||||
except KeyError:
|
||||
characters[character] = 1 # Make character position.
|
||||
|
||||
# Get all the frequncies present to speed up the reorganisation.
|
||||
frequencies = []
|
||||
|
||||
for character, frequency in characters.items():
|
||||
if frequency in frequencies:
|
||||
pass
|
||||
else:
|
||||
frequencies.append(frequency)
|
||||
|
||||
keyInverse = ""
|
||||
charactersWritten = 0
|
||||
index = 0
|
||||
|
||||
while charactersWritten < len(characters): # Align each character from least to greatest.
|
||||
for frequency in frequencies:
|
||||
for character, characterFreq in characters.items():
|
||||
if characterFreq == frequency:
|
||||
keyInverse = keyInverse + character # Not nessecarily the most efficient alignment as the final key
|
||||
charactersWritten = charactersWritten + 1 # could be made straight away instead of the inversion following.
|
||||
|
||||
# Invert List
|
||||
key = ""
|
||||
|
||||
for index in range(0, len(keyInverse)):
|
||||
indexInvert = len(keyInverse) - 1 - index
|
||||
print(index)
|
||||
key = key + keyInverse[indexInvert]
|
||||
|
||||
return key
|
||||
|
||||
print(parse(dataReference))
|
||||
print(parse(dataEncoded))
|
||||
49
Reference Scripts/Number Sorting.py
Normal file
49
Reference Scripts/Number Sorting.py
Normal file
@@ -0,0 +1,49 @@
|
||||
#!~/.pyenv/versions/3.11.6/bin/python
|
||||
|
||||
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||
#
|
||||
# -*- coding:utf-8 -*-
|
||||
# @Title: Numerical bubble sorter.
|
||||
# @Author: Cutieguwu | Olivia Brooks
|
||||
# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca
|
||||
# @Description: Simple Least to Greatest bubble sorter.
|
||||
#
|
||||
# @Script: 1.py
|
||||
# @Date Created: 20 Mar, 2024
|
||||
# @Last Modified: 21 Mar, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
|
||||
from os import path
|
||||
|
||||
with open(path.dirname(__file__) + "/sortfiles/sort1.txt", "rt") as f:
|
||||
sortData = f.readlines()
|
||||
|
||||
print(f"Fetched from ./sortfiles/sort1.txt\n{sortData}")
|
||||
print("Cleaning up...")
|
||||
|
||||
for i in range(0, len(sortData)):
|
||||
sortData[i] = int("".join(c for c in sortData[i] if c.isdigit()))
|
||||
|
||||
def is_sorted():
|
||||
IS_SORTED = []
|
||||
for i in range(0, len(sortData) - 1):
|
||||
if sortData[i] > sortData[i + 1]:
|
||||
IS_SORTED.append(False)
|
||||
else:
|
||||
IS_SORTED.append(True)
|
||||
|
||||
if False in IS_SORTED:
|
||||
IS_SORTED_FLAG = False
|
||||
else:
|
||||
IS_SORTED_FLAG = True
|
||||
return IS_SORTED_FLAG
|
||||
|
||||
while is_sorted() is False:
|
||||
for i in range(0, len(sortData) - 1):
|
||||
if sortData[i] > sortData[i + 1]:
|
||||
sortTemp = sortData[i + 1]
|
||||
sortData[i + 1] = sortData[i]
|
||||
sortData[i] = sortTemp
|
||||
|
||||
print("Finished.")
|
||||
print(f"Cleaned data:\n{sortData}")
|
||||
@@ -0,0 +1,84 @@
|
||||
#!~/.pyenv/versions/3.11.6/bin/python
|
||||
|
||||
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||
#
|
||||
# -*- coding:utf-8 -*-
|
||||
# @Title: Story Translator.
|
||||
# @Author: Cutieguwu | Olivia Brooks
|
||||
# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca
|
||||
# @Description: A simple story translator.
|
||||
#
|
||||
# @Script: main_school.py, forked from main.py
|
||||
# @Date Created: 23 Mar, 2024
|
||||
# @Last Modified: 11 April, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
|
||||
with open("story.txt", "r") as f: # Load story from file.
|
||||
story = f.read()
|
||||
|
||||
def dictionaryLoad(directory):
|
||||
with open(directory, "r") as f:
|
||||
dictionary = f.readlines()
|
||||
|
||||
return dictionary
|
||||
|
||||
dictionaryEnglish = dictionaryLoad("English.txt")
|
||||
dictionaryFrench = dictionaryLoad("French.txt")
|
||||
|
||||
def dictionaryClean(dictionary):
|
||||
for i in range(0, len(dictionary)):
|
||||
dictionary[i] = "".join(c for c in dictionary[i] if c != "\n")
|
||||
|
||||
return dictionary
|
||||
|
||||
dictionaryEnglish = dictionaryClean(dictionaryEnglish)
|
||||
dictionaryFrench = dictionaryClean(dictionaryFrench)
|
||||
|
||||
def translate(string):
|
||||
"""
|
||||
Transates a given string.
|
||||
Returns a rough translation.
|
||||
"""
|
||||
|
||||
# Begin translation.
|
||||
word = ""
|
||||
wordNew = ""
|
||||
storyTranslated = ""
|
||||
|
||||
for c in story:
|
||||
if c != " " and c != "." and c != "," and c != "\n": # Not end of word.
|
||||
word = word + c
|
||||
else:
|
||||
print("- Found special character")
|
||||
|
||||
if word.lower() in dictionaryFrench: # `word` is not empty or has a known translation;
|
||||
# additionally fixes ". " and " " events.
|
||||
|
||||
for i in range(0, len(dictionaryFrench)): # Parse the dictionary for the word's index.
|
||||
|
||||
if word.lower() == dictionaryFrench[i]: # If the word is found, fetch its english translation.
|
||||
|
||||
wordNew = dictionaryEnglish[i].lower() # Fetch the index for the corresponding word in English.
|
||||
|
||||
if word[0].isupper(): # Adjust capitalization if needed.
|
||||
wordReconstructed = wordNew[0].upper()
|
||||
|
||||
for character in wordNew:
|
||||
if wordNew.index(character) != 0:
|
||||
wordReconstructed = wordReconstructed + character
|
||||
else:
|
||||
pass
|
||||
|
||||
wordNew = wordReconstructed
|
||||
|
||||
storyTranslated = storyTranslated + wordNew + c # Place the word and its proceeding special character in the story.
|
||||
|
||||
else: # Finish building the search string and place it in the story since it's complete and cannot be translated.
|
||||
word = word + c
|
||||
storyTranslated = storyTranslated + word
|
||||
|
||||
word = ""
|
||||
|
||||
return storyTranslated
|
||||
|
||||
print(translate(story))
|
||||
62
Reference Scripts/Singluar List for Frequencies.py
Normal file
62
Reference Scripts/Singluar List for Frequencies.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!~/.pyenv/versions/3.11.6/bin/python
|
||||
|
||||
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||
#
|
||||
# -*- coding:utf-8 -*-
|
||||
# @Title: Coin Flipper.
|
||||
# @Author: Cutieguwu | Olivia Brooks
|
||||
# @Email: owen.brooks77@gmail.com | obroo2@ocdsb.ca
|
||||
# @Description: Runs a given number of trials of 5 coin flips and reports the total groupings of tails.
|
||||
#
|
||||
# @Script: 8.py
|
||||
# @Date Created: 06 March, 2024
|
||||
# @Last Modified: 07 March, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
|
||||
from random import randint
|
||||
|
||||
trials = ""
|
||||
while trials.isnumeric() == False: # Ensure that user enters a number value to iterate.
|
||||
trials = input("Enter a number of trials to run: ")
|
||||
|
||||
trials = int(trials)
|
||||
|
||||
tails = 0 # Tails in 5 throws
|
||||
tailsGroups = [0, 0, 0, 0, 0, 0] # Index indicates number of tails present, value indicates frequency of the group.
|
||||
|
||||
|
||||
def make_plural(x=int(), msg=str()):
|
||||
"""
|
||||
Appends "s" to msg if the value given isn't 1.
|
||||
Returns the modified msg.
|
||||
"""
|
||||
|
||||
if x != 1:
|
||||
msg = msg + "s"
|
||||
|
||||
return msg
|
||||
|
||||
for x in range(trials): # Main run loop, runs for number of trials given.
|
||||
msgTrial = ""
|
||||
tails = 0
|
||||
|
||||
for i in range(5): # Run a trial; flip a "coin" five times.
|
||||
flip = randint(1, 2)
|
||||
msg = ", "
|
||||
|
||||
if i == 0:
|
||||
msg = ""
|
||||
|
||||
if flip == 1:
|
||||
msg = msg + "Heads"
|
||||
else:
|
||||
msg = msg + "Tails"
|
||||
tails = tails + 1 # Record the number of tails for the trial.
|
||||
|
||||
msgTrial = msgTrial + msg
|
||||
|
||||
print(f"{msgTrial} You got {tails} tails.", end="") # Print all results of the trial at once.
|
||||
tailsGroups[tails] = tailsGroups[tails] + 1 # Increment the appropriate tails.
|
||||
|
||||
for i in range(len(tailsGroups)): # Produce results with proper grammar.
|
||||
print(make_plural(tailsGroups[i], make_plural(i, f"Rolled {i} tail") + f" in {tailsGroups[i]} trial") + ".") # Produce and print the final report, making "tail" plural if needed.
|
||||
@@ -55,4 +55,4 @@ RWHBBAIFCWIBQIRWIFIZPXNQIWOBWKNWYIPJZBYIMFJXGBAWANFIINB
|
||||
WAYFYBCPYIRAIPCWOBABHBMWNKPXYQAPJRFGRNLBYMFZRBQXMWYFXCBYPXGRJPM
|
||||
WYLTRBMBJMPCPYBIPJFHBACWNNYXZNBWMTBWKPYAQBKBYQFYGPYIRBAOFNN
|
||||
PJIRBVPCVCWOBMAFYIBNNFGBYZBWYWNLAIAAWLFMWYZPXNQVBWYLTRBMB
|
||||
JMPCIRMBBIPYFYBLBWMAWTWLJMPCRWHFYGIRBWVFNFILIPVXFNQWYWIPCVPCV
|
||||
JMPCIRMBBIPYFYBLBWMAWTWLJMPCRWHFYGIRBWVFNFILIPVXFNQWYWIPCVPCV~
|
||||
|
||||
File diff suppressed because one or more lines are too long
11
main.py
11
main.py
@@ -11,9 +11,18 @@
|
||||
#
|
||||
# @Script: main.py
|
||||
# @Date Created: 10 Apr, 2024
|
||||
# @Last Modified: 10 Apr, 2024
|
||||
# @Last Modified: 15 Apr, 2024
|
||||
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||
# ----------------------------------------------------------
|
||||
|
||||
import CutieDecrypt, CutieParser
|
||||
|
||||
with open(input("Enter path of encrypted file relative to script execution point: "), "r") as f:
|
||||
dataEncoded = "".join(c for c in f.read() if c != "\n")
|
||||
|
||||
with open("key.txt", "r") as f:
|
||||
dataReference = "".join(c for c in f.read() if c != "\n")
|
||||
|
||||
keys = CutieParser.parse(dataReference, dataEncoded)
|
||||
|
||||
print(CutieDecrypt.decrypt(dataEncoded, keys[0], keys[1]))
|
||||
Reference in New Issue
Block a user