Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Couple of tweaks to ideoCipher. keyShuffle on the other hand is 1. wholly experimental and 2. for people to generate randomly sorted keys lists.
  • Loading branch information
Jigsy1 authored Feb 9, 2023
1 parent 171a816 commit d646149
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 3 deletions.
12 changes: 9 additions & 3 deletions py3/ideoCipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
# And again, you will need at least two ideographs.
#


import os
import re
import secrets


# define(s):

IDEO_INI = "Ideo.ini"

CIPHER_TABLE = {}
FIRST_PADDING_CHANCE = 100000
SECOND_PADDING_CHANCE = 1.29
Expand Down Expand Up @@ -149,13 +151,17 @@ def ideoEncode(string):
char += 1
continue
return
# `-> End here. Having an erroneous character is a flaw.
# ¦-> End here. Having an erroneous character is a flaw.
# `-> Either type out the word manually (E.g. pounds vs. £ or add the character to the CharOrder in Ideo.ini.)
return output
# `-> Return the output.

def main():
if os.path.exists(IDEO_INI) == False:
print("Failed to create CIPHER_TABLE! {} is either missing or has been renamed.\n".format(IDEO_INI))
return
# ,-> ConfigParser wasn't handling the *.ini file very well - or at all, for that matter - so this is my working solution.
with open("Ideo.ini", "r", encoding="UTF-8") as thisFile:
with open(IDEO_INI, "r", encoding="UTF-8") as thisFile:
for thisLine in thisFile:
thisNewLine = thisLine.split("=", 1)
if len(thisNewLine) < 2:
Expand Down
117 changes: 117 additions & 0 deletions py3/keyShuffle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# keyShuffle.py (Experimental) by Jigsy (/~https://github.com/Jigsy1) released under the Unlicense.
#
# For shuffling the (default) Ideo.ini keys automatically rather than doing it manually.

import os
import re
import secrets
import time


# define(s):

NEWLINE_REGEX = r"[\n\r]+"
# `-> For splitting on main().

TIMESTAMP = str(time.time())

IDEO_INI = "Ideo.ini"
OUTPUT_FILE = "Ideo_{}.ini".format(TIMESTAMP)


# Function(s):

def main():
if os.path.exists(IDEO_INI) == False:
print("Aborting. {} is either missing or has been renamed.\n".format(IDEO_INI))
return
START_INDEX = 0
# `-> If you wish to use the mIRC version, change this to 1. Otherwise, leave it at 0.
if START_INDEX < 0 or START_INDEX > 1:
print("Aborting. START_INDEX must be either 0 (Python) or 1 (mIRC).\n")
return
SHUFFLE = []
UNUSED = ""
# ,-> ConfigParser wasn't handling the *.ini file very well - or at all, for that matter - so this is my working solution.
with open(IDEO_INI, "r", encoding="UTF-8") as thisFile:
for thisLine in thisFile:
thisNewLine = thisLine.split("=", 1)
if len(thisNewLine) < 2:
continue
theseChars = re.split(NEWLINE_REGEX, thisNewLine[1])
if len("".join(theseChars)) > 0:
# `-> Ignore any entries with zero characters after the =. E.g. Extra=
if thisNewLine[0] == "CharOrder":
CHAR_ORDER = "".join(theseChars)
continue
if thisNewLine[0] == "Unused":
UNUSED = "".join(theseChars)
continue
chars = "".join(theseChars)
char = 0
while char < len(chars):
SHUFFLE.append(chars[char])
char += 1
# ,-> Shuffle the list randomly at least once.
KEY_COUNT = len(SHUFFLE)
PRE_SHUFFLE = []
while KEY_COUNT > 0:
randomIndex = secrets.choice(range(0, len(SHUFFLE)))
PRE_SHUFFLE.append(SHUFFLE[randomIndex])
del SHUFFLE[randomIndex]
KEY_COUNT -= 1
SHUFFLE.clear()
SHUFFLE = PRE_SHUFFLE.copy()
del PRE_SHUFFLE
# ,-> Second shuffle, but write them out this time.
with open(OUTPUT_FILE, "w", encoding="UTF-8") as outputFile:
outputFile.write("# File generated at: {}\n".format(TIMESTAMP))
if START_INDEX == 1:
outputFile.write("#\n")
outputFile.write("# This is only compatible with the mIRC version of ideoCipher.\n")
outputFile.write("\n")
outputFile.write("[Settings]\n")
outputFile.write("CharOrder={}\n\n".format(CHAR_ORDER))
outputFile.write("[Keys]\n")
KEY_COUNT = len(CHAR_ORDER)
CHARS_PER_LINE = int((len(SHUFFLE) / len(CHAR_ORDER)))
# CHARS_PER_LINE = int(((len(SHUFFLE) / len(CHAR_ORDER)) - 1))
# `-> Subtract one line because we need to split between Space and Padding on the last line. (Results in longer Space and Padding.)
while KEY_COUNT > 0:
KEY_LINE = ""
KEY_SUBCOUNT = 0
while KEY_SUBCOUNT < CHARS_PER_LINE:
randomIndex = secrets.choice(range(0, len(SHUFFLE)))
KEY_LINE = KEY_LINE + SHUFFLE[randomIndex]
del SHUFFLE[randomIndex]
KEY_SUBCOUNT += 1
outputFile.write("{}={}\n".format(START_INDEX, KEY_LINE))
START_INDEX += 1
KEY_COUNT -= 1
KEY_COUNT = 2
CHARS_PER_LINE = int((len(SHUFFLE) / 2))
while KEY_COUNT > 0:
KEY_LINE = ""
KEY_SUBCOUNT = 0
while KEY_SUBCOUNT < CHARS_PER_LINE:
randomIndex = secrets.choice(range(0, len(SHUFFLE)))
KEY_LINE = KEY_LINE + SHUFFLE[randomIndex]
del SHUFFLE[randomIndex]
KEY_SUBCOUNT += 1
if KEY_COUNT == 2:
outputFile.write("{}={}\n".format("Space", KEY_LINE))
else:
outputFile.write("{}={}\n".format("Padding", KEY_LINE))
KEY_COUNT -= 1
if UNUSED != "":
outputFile.write("Unused={}\n".format(UNUSED))
if len(SHUFFLE) > 0:
# `-> Hopefully this won't be used. If it is, just cut and paste them into either Space or Padding manually I guess?
outputFile.write("Leftover={}\n".format("".join(SHUFFLE)))
print("Done. Please rename {} to {} before using.\n".format(OUTPUT_FILE, IDEO_INI))

if __name__ == "__main__":
main()


# EOF

0 comments on commit d646149

Please sign in to comment.