Skip to content

Instantly share code, notes, and snippets.

@nerun
Last active January 16, 2024 13:16
Show Gist options
  • Save nerun/a2580836aeb4b8f3a92b4110058d6e7f to your computer and use it in GitHub Desktop.
Save nerun/a2580836aeb4b8f3a92b4110058d6e7f to your computer and use it in GitHub Desktop.
CUNEICRYPT encrypts or decrypts a text file to stdout. It's a keyless cipher that replaces each printable character in a text file with a character in the cuneiform unicode block. It is written in Python for study and entertainment purposes only. This is a very weak encryption, do not use it to protect your data.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
args = sys.argv
def color(code, txt):
# 1 Red 3 Yellow 5 Purple 7 Light Gray
# 2 Green 4 Blue 6 Cyan (Light Blue) 8 Black
return '\033[3' + str(code) + 'm' + str(txt) + '\033[00m'
def unicode_list(x,y):
z=[]
for i in range(x, 1 + y, 1):
if str.isprintable(chr(i)):
z.append(chr(i))
return z
def crypt(opt):
try:
file = open(args[2], 'r')
except:
print( color(1,"ERROR. No such file or directory: \"%s\"."% (args[2])) )
sys.exit()
text = file.read()
file.close()
# https://en.wikipedia.org/wiki/Latin_script_in_Unicode
# len(latin) = 317
latin = unicode_list(0x0000, 0x017F)
# https://en.wikipedia.org/wiki/Cuneiform_(Unicode_block)
# len(cuneiform) = 317
cuneiform = unicode_list(0x12000, 0x1213C)
if opt == "-e":
for char in latin:
text = text.replace(char, cuneiform[latin.index(char)])
else: # opt == "-d"
for char in cuneiform:
text = text.replace(char, latin[cuneiform.index(char)])
# print to stdout but delete the last line because python always adds an
# empty line at the end.
print(text[:-1])
help = """CUNEICRYPT - encrypts or decrypts a text file to stdout.
Cuneicrypt is a keyless cipher that replaces each printable character in a text
file with a character in the cuneiform unicode block. It is written in Python
for study and entertainment purposes only. This is a very weak encryption, do
not use it to protect your data.
Use: cuneicrypt [OPTION] [FILE]
Options:
-e encrypts text FILE and print the result to stdout
-d the same, but decrypts
Copyright:
(c) 2024 Daniel Dias Rodrigues <[email protected]>
https://gist.github.com/nerun/a2580836aeb4b8f3a92b4110058d6e7f
License:
This program is free software; you can redistribute it and/or modify it
under the terms of the Creative Commons Zero 1.0 Universal (CC0 1.0) Public
Domain Dedication (https://creativecommons.org/publicdomain/zero/1.0/)."""
if len(args) >= 2:
if args[1].lower() == "-e" or args[1].lower() == "-d":
crypt(args[1].lower())
elif args[1].lower() == "-h" or args[1].lower() == "--help":
print(help)
else:
print( color(1, "ERROR. No such option: \"%s\".\n" %(args[1])) )
print(help)
else:
print( color(1, "ERROR. Missing arguments.\n") )
print(help)
@nerun
Copy link
Author

nerun commented Jan 15, 2024

Installation

Download cuneicrypt.py, rename it to cuneicrypt, move it to one of:

  • ~/.local/bin
  • /usr/bin
  • /usr/local/bin

Usage

You should be capable to use it in your Linux terminal, in any folder. Start with:

$ cuneicrypt --help

If you don't want to install it, "cd" to the folder where is cuneicrypt.py and:

$ ./cuneicrypt.py --help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment