Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions Cryptex.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import random"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# We create a dictionary with the equivalences character-ASCII code and ASCII code-character\n",
"englishcodes=list(range(32,127))\n",
"english_encrypting={}\n",
"for i in range(95):\n",
" english_encrypting[chr(englishcodes[i])]=englishcodes[i]\n",
"english_decrypting=dict()\n",
"for i in range(95):\n",
" english_decrypting[englishcodes[i]]=chr(englishcodes[i])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"unique_equivalences = set()\n",
"code_generator=[str(1), str(0), str(1), str(0), str(1), str(0), str(1), str(0), str(1), str(0)]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# We create the encrypting code each of the 95 characters in the english alphabet\n",
"while len(unique_equivalences)<95:\n",
" random.shuffle(code_generator)\n",
" shuffled=(\"\".join(code_generator))\n",
" unique_equivalences.add(shuffled)\n",
"equivalences=list(unique_equivalences)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# We generate a dictionary with the ASCII code-Emcripted code and the Encrypted code-ASCII code equivalences\n",
"rosetta_stone_decrypting={}\n",
"for i in range(95):\n",
" rosetta_stone_decrypting[equivalences[i]]=englishcodes[i]\n",
"rosetta_stone_encrypting={}\n",
"for i in range(95):\n",
" rosetta_stone_encrypting[englishcodes[i]]=equivalences[i]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def encryption():\n",
" text2encrypt=input(\"What text do you wish to encrypt? \")\n",
" blanklist=[]\n",
" for character in text2encrypt:\n",
" blanklist.append(character)\n",
" encrypting_characters=[]\n",
" for i in blanklist:\n",
" encrypting_characters.append(english_encrypting.get(i))\n",
" rosetta_characters=[]\n",
" for i in encrypting_characters:\n",
" rosetta_characters.append(rosetta_stone_encrypting.get(i))\n",
" encrypted_input = (\"-\".join(rosetta_characters))\n",
" return encrypted_input"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def decryption():\n",
" text2encrypt=input(\"What text do you wish to decrypt? \")\n",
" \n",
" blanklist=text2encrypt.split(\"-\")\n",
" rosetta_characters=[]\n",
" for i in blanklist:\n",
" rosetta_characters.append(rosetta_stone_decrypting.get(i))\n",
" english_characters=[]\n",
" for i in rosetta_characters:\n",
" english_characters.append(english_decrypting.get(i))\n",
" decrypted_output=(\"\".join(english_characters))\n",
" return decrypted_output"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
145 changes: 145 additions & 0 deletions Encrypting-Decrypting.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"englishcodes=list(range(32,127))\n",
"english_encrypting={}\n",
"for i in range(95):\n",
" english_encrypting[chr(englishcodes[i])]=englishcodes[i]\n",
"english_decrypting=dict()\n",
"for i in range(95):\n",
" english_decrypting[englishcodes[i]]=chr(englishcodes[i])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"unique_equivalences = set()\n",
"import random\n",
"code_generator=[str(1), str(0), str(1), str(0), str(1), str(0), str(1), str(0), str(1), str(0)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"while len(unique_equivalences)<95:\n",
" random.shuffle(code_generator)\n",
" shuffled=(\"\".join(code_generator))\n",
" unique_equivalences.add(shuffled)\n",
"equivalences=list(unique_equivalences)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rosetta_stone_decrypting={}\n",
"for i in range(95):\n",
" rosetta_stone_decrypting[equivalences[i]]=englishcodes[i]\n",
"rosetta_stone_encrypting={}\n",
"for i in range(95):\n",
" rosetta_stone_encrypting[englishcodes[i]]=equivalences[i]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def encryption_process():\n",
" text2encrypt=input(\"What text do you wish to encrypt? \")\n",
" blanklist=[]\n",
" for character in text2encrypt:\n",
" blanklist.append(character)\n",
" encrypting_characters=[]\n",
" for i in blanklist:\n",
" encrypting_characters.append(english_encrypting.get(i))\n",
" rosetta_characters=[]\n",
" for i in encrypting_characters:\n",
" rosetta_characters.append(rosetta_stone_encrypting.get(i))\n",
" encrypted_input = (\"-\".join(rosetta_characters))\n",
" return encrypted_input"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def decryption_process():\n",
" text2encrypt=input(\"What text do you wish to decrypt? \")\n",
" \n",
" blanklist=text2encrypt.split(\"-\")\n",
" rosetta_characters=[]\n",
" for i in blanklist:\n",
" rosetta_characters.append(rosetta_stone_decrypting.get(i))\n",
" english_characters=[]\n",
" for i in rosetta_characters:\n",
" english_characters.append(english_decrypting.get(i))\n",
" decrypted_output=(\"\".join(english_characters))\n",
" return decrypted_output"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Do you want to encrypt or decrypt a message? (please type encrypt/decrypt)decrypt\n",
"What text do you wish to decrypt? 0110001011-1101011000-0010111010-1101100010-1001100110-0100110110-0100110110-1101011000-0111001100\n",
"IronBeers\n"
]
}
],
"source": [
"decision=input(\"Do you want to encrypt or decrypt a message? (please type encrypt/decrypt)\")\n",
"while (decision!=\"encrypt\") and (decision!=\"decrypt\"):\n",
" decision=input(\"Oops! I didn't understand! Do you want to encrypt or decrypt?\"\n",
" \"(please type encrypt or decrypt)\")\n",
"if decision == \"encrypt\":\n",
" print(encryption_process())\n",
"else:\n",
" print(decryption_process())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
65 changes: 65 additions & 0 deletions Refactoring.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# We import Cryptex, a library containing the formulas and dictionaries needed to encrypt and decrypt\n",
"\n",
"import Cryptex"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Do you want to encrypt or decrypt a message? (please type encrypt/decrypt)encryot\n",
"Oops! I didn't understand! Do you want to encrypt or decrypt?(please type encrypt or decrypt)encrypt\n",
"What text do you wish to encrypt? Hello world!\n",
"0110100101-0110010011-0110010110-0110010110-0110010101-0011100011-1100100101-0110010101-0001101110-0110010110-1000011110-1000100111\n"
]
}
],
"source": [
"# We generate the flow of the program, where we define if we are doing an encryption \n",
" # or a decryption and then run the optimal formula\n",
"decision=input(\"Do you want to encrypt or decrypt a message? (please type encrypt/decrypt)\")\n",
"while (decision!=\"encrypt\") and (decision!=\"decrypt\"):\n",
" decision=input(\"Oops! I didn't understand! Do you want to encrypt or decrypt?\"\n",
" \"(please type encrypt or decrypt)\")\n",
"if decision == \"encrypt\":\n",
" print(Cryptex.encryption())\n",
"else:\n",
" print(Cryptex.decryption())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
25 changes: 25 additions & 0 deletions Refactoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


# We import Cryptex, a library containing the formulas and dictionaries needed to encrypt and decrypt

import Cryptex


# In[3]:


# We generate the flow of the program, where we define if we are doing an encryption
# or a decryption and then run the optimal formula
decision=input("Do you want to encrypt or decrypt a message? (please type encrypt/decrypt)")
while (decision!="encrypt") and (decision!="decrypt"):
decision=input("Oops! I didn't understand! Do you want to encrypt or decrypt?"
"(please type encrypt or decrypt)")
if decision == "encrypt":
print(Cryptex.encryption())
else:
print(Cryptex.decryption())

Binary file added __pycache__/Cryptex.cpython-38.pyc
Binary file not shown.