Skip to content

weiliamu/simple-cipher

Repository files navigation

simple-cypher

simple-cypher is a simple Python script that allows you to encrypt text. The encryption is done either by simple substitution or by a symmetric key (a secret key). This program is intended for simple or educational uses.

Explanation of the content

  • simple-cypher.py : main file called to encrypt a text
  • cypher-functions.py : module that contains the necessary functions
  • LUT_roman.py : look-up table to convert text with Roman characters (numbers)
  • LUT_greek.py : look-up table to convert text with Greek characters
  • LUT_chinese.py : look-up table to convert text with Chinese characters (numbers)
  • LUT_random.py : look-up table to convert text with Random characters
  • examples/ : contains practical examples (text, key, and results)

Examples of results

Greek

ΓΡΑΝ ΑΒΑΟ ΒΞΔΜ ΑΧΑΤ ΑΚΑΟ ΑΘΒΞ ΓΔΑΓ ΑΠΑΤ ΑΟΒΞ ΔΒΑΧ ΑΟΑΖ ΒΞΒΖ ΒΗΒΠ ΒΞΒΕ ΒΝΒΕ ΒΖΒΠ ΒΞΔΔ ΑΠΑΟ ΑΕΑΠ ΑΟΒΠ ΒΞΓΦ ΑΟΑΘ ΑΝΑΒ ΑΟΑΕ ΑΑΑΕ ΑΚΑΖ ΑΕΒΞ ΔΒΑΧ ΑΟΑΖ ΒΞΒΛ ΒΠΒΞ ΒΕΒΝ ΒΙΒΘ ΒΠΒΞ ΔΟΑΚ ΑΝΑΞ ΑΥΑΝ ΑΠΑΩ ΒΠΒΞ ΓΤΑΙ

Chinese

七七二七 一五二五 四二零八 五八三二 一四三六 一二五五 八八零五 三三一九 二七五三 九二三四 二九一九 四八三四 五五七六 五一三三 五八三三 四七七六 四零九三 一六二七 二零三四 二七五四 五一七九 一九三二 四九一 四二零八 五五七六 一五二五 七七二七 五一七九

Roman

XVVL XVVD LLIM ILII VVVD DXLL LLXI DVII VDLL VIIL VDXC LLML MCLD LLMM LMMM MLLD LLVL DVVD XLDV VDLD LLXC VDDX VLXV VDXL DDXL VVXC XLLL VIIL VDXC LLLV LDLL MMLM DMMD LDLL IDVV VLVC XXVL DVID LDLL XMVX

Options, practical case

simple-cypher.py [action] [file] [options]

[action] : chose the encryption direction, [encrypt] or [decrypt]. By default the encryption is a substitution. To use symetric encryption, use the --key, -k [KEY] option.

[file] : File name of the message to encrypt / decrypt (typically a .txt file).

[options] :

  • --help, -h : show help and description
  • --key, -k [KEY] : Use a symetric encryption, the file path of the must be provided with [KEY].
  • --verbose, -v : Verbose mode, describe the script steps in the terminal.
  • --output, -o [OUTPUT] : Define a file name for the result (typically a .txt file).
  • --length, -l [LENGTH] : Length of the grouping of the results (how many caracters are put together, 0 is for no spacing).
  • --spacing, -s [SPACING] : Specify a character used for the spacing if a length is precised. (Default is a space ' ' character). --type, -t [TYPE] : Type of the characters used to encrypt the message. Standard types are : [greek] [roman], [chinese] or [random] (default is greek). More type can be created by customising a LUT file.

python3 simple-cypher.py encrypt message.txt

python3 simple-cypher.py encrypt message.txt -k key.txt -t chinese

python3 simple-cypher.py decrypt message.txt -k key.txt -t random -v -o result.txt -l 6 --spacing -

How it works

The message to be encrypted is processed letter by letter. Each letter is translated into a two-digit number using a first look-up table. Then, a second look-up table translates each number into a group of two characters. This encryption is similar to a substitution. In the case of symmetric encryption, a key is used to shift the value of the number. This prevents the same character from always being encrypted in the same way.

Substitution

character -> double digit number -> double characters

Symetric

characters -> double digit number -> increment by the value of the caracter's key -> double characters

LUT : look-up table

LUT files contains the look-up table to convert a number into a caracters. Users can create their own LUT or modifying the existing ones. Also, more caracters can be specify, for instance to support other languages (by default, this program is made for english caracters).

About

A simple Python script that allows you to encrypt text, by substitution or with a symetric key.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages