This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wojbie's profile picture

Enigma - Encryption API For Your Programs v4

Started by Wojbie, 25 September 2013 - 04:45 AM
Wojbie #1
Posted 25 September 2013 - 06:45 AM
Enigma - Encryption API For Your Programs v4.5

Enigma is a Simple to use encryption software made in order to ensure security of your programs on SMP servers. Multiple functions allow you to use it in the way you feel is best for you!

Encryption system is based of Military version of Enigma Machine.
I am trying to keep it as close to how original Enigma Machine worked as i can.
You can select 3 out of 10 predefined Rotors. You then select starting positions of said Rotors.
That gives 857375000 unique Rotor/Start Position combinations.
You can read more about it in http://en.wikipedia..../Enigma_machine
I have made few modification to it in order to be able to encrypt all common use symbols.

Download Here: http://pastebin.com/WYuNMxQx
Or ingame using command:
pastebin get WYuNMxQx enigma

Features List:
  • Encryption/Decryption of strings
  • 100% safe to your programs - no risk of corruption - if Enigma sees symbol it don't understands it simply writes it on without encryption.
Methods:

--# create a new crypter
crypter =  enigma.crypt(A,B,C,a,b,c)
--# A,B,C,a,b,c are starting positions on crypter.
--# where A,B,C are numbers 1-10 that tell enigma witch out of 10 standard rotors to use and a,b,c are numbers from 1-96 that set starting positions of said rotors.
--#A,B,C can also be a valid rotor tables.Valid rotor table is table containing numbers from 1-96 in random order.

--# encrypting string
ciphertext = crypter("plaintext")

--# duplicating crypter
crypterclone = crypter.copy()

--# to decrypt create crypter with same  starting positions as one used to encrypt
decrypter =  enigma.crypt(A,B,C,a,b,c)
decrypter(ciphertext) -> "plaintext"

--# to stop crypter from being able to be copied simply add true flag at end of attributes
nocopycrypter =  enigma.crypt(A,B,C,a,b,c,true)

--# You can also stop duplication at later time by running
nocopycrypter.blockCopy()


Here is example program:
Spoiler

--# get command line arguments
tArgs={...}

--# load the enigma API
os.loadAPI("enigma")

--# create your crypter
local crypter = enigma.crypter(1,1,1,1,1,1)

--# copy it
local crypterclone = crypter.copy()

--# crypt first argument from command line and print it
local secret=crypter(tArgs[1])
print(secret)

--# decrypt it and print decrypted
local truth = crypterclone(secret)
print(truth)

Screenshot of that program in action:

Notes:
  • In case of A,B,C instead of using numbers 1-10 for standard rotors you can make your own and give it instead of the number. Rotor is table containing numbers from 1-96 in random order.
  • Instead of loading enigma as API you can use it as file encryption program. Simply use "enigma <absolute path> and after few quick questions selected fill will be encrypted.
  • Enigma was secure at time of its creation. In this days it is easy to brute force. This program was not made to be a secure encryptor instead it is a recreation of actual enigma method of encryption.
Archived older program version
SpoilerEnigma - Encryption Software For Your Programs v3

Enigma is a Simple to use encryption software made in order to ensure security of your programs on SMP servers. Multiple functions allow you to use it in the way you feel is best for you!

Encryption system is based of Military version of Enigma Machine.
I am trying to keep it as close to how original Enigma Machine worked as i can.
You can select 3 out of 10 predefined Rotors. You then select starting positions of said Rotors.
That gives 857375000 unique Rotor/Start Position combinations.
You can read more about it in http://en.wikipedia..&#46;&#46;/Enigma_machine
I have made few modification to it in order to be able to encrypt all common use symbols.

Download Here: http://pastebin.com/NKhvzq2B
Or ingame using command:
pastebin get NKhvzq2B enigma
(requires http-api to be active)

Features List:
  • Encryption/Decryption of files
  • Decryption and running programs from drive
  • Creating Self-Decrypting Programs for fast usage.
  • 100% safe to your programs - no risk of corruption - if Enigma sees symbol it don't understands it simply writes it on without encryption.
Program use:
Spoiler
  1. enigma code [path] - Encrypt/Decrypt [path] file into [path].code file.
  2. enigma codein [path] - Encrypt/Decrypt [path] file into itself (overwrites content) file.
  3. enigma run [path] - Decrypt [path] file and run it. Effects on non coded file are undefined
  4. enigma exec [path] - Encrypt/Decrypt [path] file into [path].code file and add self-decrypting code. This file can be used without main Enigma file. Simply run it and enter Pass.
  • Use enigma help or enigma ? for in-game Help-page
  • Use enigma help2 or enigma ?2 for in-game Advanced Usage

Program is made to fit all 4 possible types of computer advanced or normal / turtle or computer no matter
Code Entering GUI Will change itself in order to fit your Needs.


Side Features include:
  • Ability to Hide/Show numbers you are entering
  • Full touchscreen Control on Advanced Computers/Turtles
  • Ability to enter Basic Mode - Simple menu that uses print() and read()
Example of use:
SpoilerIn this example i am assuming you are creating self-decrypting file from
a hello file you have on your disk.
  1. enigma exec [path] - where [path] is absolute path to hello file
  2. You will see one of 4 Screens Depending on Machine you are running this program on. Now you select from 10 Rotors you want to use. You can use same Rotor more than once. Then you enter starting positions of rotors. Remember all 6 numbers. For More info about Rotors and how they work see: http://en.wikipedia...._machine#Rotors
  3. Now you will have hello.code file in same directory as hello file. Thats Self-decrypting program you created. You can rename it and move it wherever you need it.
  4. Remember to hide unencrypted hello to somewhere safe - you don't want anyone getting this one do you? :P/>
  5. When you run hello.code file you will see familiar Rotor Setup Screen. Enter Same Rotors and Starting positions in order to begin encryption. After you enter it hello program will be decoded and run.
  6. Thats it! Tx for read and hope you like this program.

Change-log:
Spoilerv0.9 - Initial Release on Ask A Pro Sub-forum
v1.0 - Release On Programs Sub-forum - Added Turtle detection codes and 2 bug fixes
v2.0 - Ability to select 3 rotors from selection of 10 like in Basic Military version of enigma
v3.0 - Fixed up run string command using my new knowledge

Plans For Future:
Spoilerv3.5 - Clean Up Code :D/>
v4.0 - Implementation of Plugboard from Navy Military version of enigma in form hidden of .plugboard file
v5.0 - Encrypting files in mass,encrypting Directories.
Edited on 01 December 2015 - 07:24 AM
PixelToast #2
Posted 25 September 2013 - 12:48 PM
interesting :)/>
http://www.youtube.com/watch?v=V4V2bpZlqx8
i might make a cracker for it :3
Wojbie #3
Posted 25 September 2013 - 01:31 PM
Feel free to do so. It would please me greatly. :P/>

If you peek in advanced usage in program help you will see that this exact video series inspired me to make it ;D
This version only has 857 375 possible different combinations.
With interchangeable Rotors (3 out of 10) [planed in v2] that would increase into 617 310 000 possible different combinations.
I am not sure if i will implement Plugboard.
I am thinking about implementing Reflector that removes flaw from this video. But that will wait until someone Codes Bomba. :D/>

EDIT : Hmm i need to test how easy its to brute-force it - probably real easy :(/>
But who cares its a Enigma!

EDIT 2 :I Could increase security by selecting 10 from 10 rotors- but then it would not be Enigma anymore… On other hand i already increased alphabeth from orginal to include Uppercase letters and symbols like !@#$$%^&amp;*()_+{}||"?…

EDIT 3 : OK i am making v2 right away - i managed to brute-force all possible passes in 47.5 minutes. That was on
631 characters long file test file with last tested combination as password. Still kinda week.

EDIT 4 : Version 2 is ready and posted - now it will take about a 32,9 days to brute force trough all possible combinations. On side note i seem to really like editing my own post….. I think its my ego.

EDIT 5 : Note here that times i posted here are made using ingame brute-force code - taking encoded file outside of ComputerCraft would decrease decoding time significantly.
PixelToast #4
Posted 25 September 2013 - 07:21 PM
Why would encryption for programs even be needed? All the programs made here are meant to be Open-Source only.
Passwords I would see encryption for, but this I wouldn't be able to find a use for it.
Good job on the GUIs though!
obufuscating code is not the only use for encryption.
Wojbie #5
Posted 25 September 2013 - 07:24 PM
It was made for 3 reasons
  1. Because i wanted to make Working version of Enigma
  2. Because people keep stealing my tree-cutting turtle
  3. Because when you keep something like password for wireless communication in program then with some encrypting and regularly changed passwords you can ensure that even if someone stole your data password still is secure.
  4. Because why not? Its feels nice to make something :P/>
amtra5 #6
Posted 26 September 2013 - 07:02 PM
It was made for 3 reasons
  1. Because i wanted to make Working version of Enigma
  2. Because people keep stealing my tree-cutting turtle
  3. Because when you keep something like password for wireless communication in program then with some encrypting and regularly changed passwords you can ensure that even if someone stole your data password still is secure.
  4. Because why not? Its feels nice to make something :P/>/>

Heh, seems a bit casual gotta love your reasons. I don't know anyone who would put their passwords into a plain-text file though haha!
You might make an invisibility cloak (you know, Harry Potter?) for your Turtle as well… someone needs to make that, so people stop stealing your turtles.
[video]
http://youtube.com/watch?v=STE7OnC2V2E
[/video]
Wojbie #7
Posted 01 March 2015 - 10:53 AM
Update and Direction Change!

This program got changed into an API for you to use in your programs as needed!
Older version moved to archive spoiler at bottom of post.
New version is faster and uses metatables!
Hope it fits your needs.

PS. Could i request Admin to move this into Utilites and API's subforum? As it is no longer a simple program.
direTry20 #8
Posted 31 October 2015 - 04:09 AM
why do u need to clone the crypter, why bother to, it doesn't seem that u need to. idk
Edited on 31 October 2015 - 03:11 AM
Wojbie #9
Posted 31 October 2015 - 08:21 AM
why do u need to clone the crypter, why bother to, it doesn't seem that u need to. idk

Because crypter has a state it's set to. When you encrypt something that state changes. And to decrypt you need crypter in same state as it was when encrypting the message. The copy function is there simply for convenience sake. You can create same crypter using same numbers. It's just simpler to copy one.
Edited on 31 October 2015 - 07:22 AM
jaredallard #10
Posted 07 November 2015 - 01:02 AM
Can we have a mathematical proof of this right now? It doesn't appear to exactly follow the original machine. Also, I'd like to see it not not churn out the same letter as the original, as that was a big issue for the original machine. That would make it less crackable! Also, what about the front board sockets? Those increased the complexity and were only issued in the military versions.
Wojbie #11
Posted 01 December 2015 - 08:19 AM
Update - version 4.5
  • Added sanity test to ensure most common bugs are stopped.
  • Added ability to disable making copies of cypher. It can be defined when creating a cypher or at later time by running block function inside it.
  • Moved the cypher state inside the secure local table. This stops outside functions for touching the state and allows the copy blocking to be secure. Also its more secure than in last version so yea.
And now for the response to really old post. Sorry its late but for some reason i did not get notification about the post.
Can we have a mathematical proof of this right now? It doesn't appear to exactly follow the original machine. Also, I'd like to see it not not churn out the same letter as the original, as that was a big issue for the original machine. That would make it less crackable! Also, what about the front board sockets? Those increased the complexity and were only issued in the military versions.

It is based on one of first enigma designs. That means one turnover notch per a rotor and 3 rotors at same time.
I will do a logical proof. Input letter -> 1st rotor -> 2nd rotor -> 3th rotor -> reflector -> backwards 3th rotor -> backwards 2nd rotor -> backwards 1st rotor -> output letter. Then step 1st rotor and repeat with next letter. This is how enigma worked and how this program works.

The difference from original machine in in the rotors itself. This program don't incorporate the turnover notch between letters position (Its between last and first letter). Also the rotors itself are custom made for the program. Because lua uses more symbols than original enigma i had to extend the rotors to contain all those letters and symbols. That means rotors are extended from original 26 letters into 96 possible letters.

As for not churning the same letter as original? That is error inside the enigma logic itself. It can not be removed without changing the way enigma works.
Switchboard was planned but i threw it out after i coded in ability for people to provide their own rotor tables. It gives same complexity extension in the end.
Edited on 01 December 2015 - 11:48 AM
LDDestroier #12
Posted 01 December 2015 - 11:50 AM
Cool, now you are an official member of the German Nationalist-Socialist party! Sieg heil!
LDDestroier #13
Posted 01 December 2015 - 01:55 PM
I'm going to make an encrypted decentralized chat out of this. Can you suggest a funny name for it? I'm not too good with program names.
Lupus590 #14
Posted 01 December 2015 - 03:14 PM
I'm going to make an encrypted decentralized chat out of this. Can you suggest a funny name for it? I'm not too good with program names.

Hush? Whisper? EDC?
LDDestroier #15
Posted 01 December 2015 - 03:44 PM
Pretty good names. All I gotta do now is learn how to use it, wah!
Wojbie #16
Posted 07 December 2015 - 01:33 PM
Update - version 4.6
  • Fixed logic error in encryption algorithm that in edge case caused encrypted code to be corrupted.
WARNING: THIS UPDATE CHANGES THE ENCRYPTION ALGORITHM. IT IS INCOMPATIBLE WITH FILES ENCRYPTED WITH OLDER VERSION.
Edited on 07 December 2015 - 12:33 PM