6 Commits

Author SHA1 Message Date
Cutieguwu
34a6e23eef Things I shall disclose. 2024-04-23 12:30:02 -04:00
Cutieguwu
a7b256960e Added Reference Scripts 2024-04-15 13:02:21 -04:00
Cutieguwu
fb88599663 Revising standards, added fallback for testing, Improved in-script commenting. 2024-04-15 11:42:28 -04:00
Cutieguwu
c1d2299b67 Added manual encrypted data directory pointing. 2024-04-15 11:39:01 -04:00
Cutieguwu
4da09caf87 Cleaned up and corrected last edit date. 2024-04-15 11:27:50 -04:00
Cutieguwu
d874c43814 Began automation in main.py. Set interfacing standards and parameters for CutieParser. 2024-04-15 11:24:11 -04:00
7 changed files with 439 additions and 226 deletions

View File

@@ -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,27 @@ 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("/home/beartech-server/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 = "BWIYFMPARQNZXCJKGTLVHOESDU" # Temporary - Faux testing key.
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,
"WYNJBOSRFUHVTPCASGMIKLYEXD",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
))

View File

@@ -11,7 +11,7 @@
#
# @Script: CutieParser.py
# @Date Created: 10 Apr, 2024
# @Last Modified: 11 Apr, 2024
# @Last Modified: 15 Apr, 2024
# @Last Modified by: Cutieguwu | Olivia Brooks
# ----------------------------------------------------------
@@ -22,5 +22,3 @@
with open("dataReference.txt", "r") as f:
data = f.read()
":"

View 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}")

View File

@@ -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))

View 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.

File diff suppressed because one or more lines are too long

11
main.py
View File

@@ -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]))