### Author Topic: Simple Encryption Algorithm  (Read 8548 times)

#### cman

• Member
• Posts: 222
##### Simple Encryption Algorithm
« on: November 25, 2015, 04:29:18 AM »
What is a simple but fairly secure algorithm for encrypting text files? I don't know much about cryptography , so I though someone could point me to an algorithm I could just "plug into" my project. It almost seems like I could just "make one up" by applying a sequence of operations to the characters in the files to encrypt them , and then reversing the process to decrypt  , but I'm sure there is more to encryption then that.  Thanks for any information...

#### dedndave

• Member
• Posts: 8827
• Still using Abacus 2.0
##### Re: Simple Encryption Algorithm
« Reply #1 on: November 25, 2015, 04:42:51 AM »
assuming you want a plain text file when encrypted.....

just use a translation table for characters:
30 to 39 hex, inclusive (numeric digits 0 to 9)
41 to 5A hex, inclusive (upper case letters)
61 to 7A hex, inclusive (lower case letters)

#### FORTRANS

• Member
• Posts: 1077
##### Re: Simple Encryption Algorithm
« Reply #2 on: November 25, 2015, 05:22:15 AM »
Hi,

What is a simple but fairly secure algorithm for encrypting text files?

That depends on how hard you want to work and who you want
to hide the text from.  Dave's idea is good if you want to hide text
from someone that is not very informed about cryptography.  Though
I would add punctuation symbols and white space.  That can create
simple text files, so you do not have to worry about binary files.

Another simple process is to exclusive or your text with a pattern
generated by a pass phrase.  Prompt for the pass phrase, AND it
with 01FH to preserve the high bits of the text file, and exclusive or
the phrase with your text file.  Don't use a very short phrase though.
To recover the original text, repeat the process with the same pass
phrase.

Either of those algorithms will encrypt your text against most people.
If you want to hide text from more knowledgeable people, you will
need a better algorithm.

Regards,

Steve N.

#### ragdog

• Member
• Posts: 610
##### Re: Simple Encryption Algorithm
« Reply #3 on: November 25, 2015, 05:32:18 AM »
Hello

A simply encryption is a Xor encryption but not secure.

#### cman

• Member
• Posts: 222
##### Re: Simple Encryption Algorithm
« Reply #4 on: November 25, 2015, 06:11:02 AM »
Ok , thanks for the replies ! Searching around on the internet I see simple algorithms like "TEA" and "Threefish" and other algorithms that are composed of a few simple lines of code. I wonder if any of these would be sufficient. I guess I could pull an "Algorithm Analysis" textbook off my shelf , I guess I'm getting lazy.

#### hutch--

• Member
• Posts: 7542
• Mnemonic Driven API Grinder
##### Re: Simple Encryption Algorithm
« Reply #5 on: November 25, 2015, 08:29:37 AM »
There are two items in the MASM32 SDK that can help you if you are working in MASM. A simple but fast stream XOR algo called "xordata" in the masm32 library and a specialised tool called RPG.EXE (example05\rpg\"that creates reasonably good quality random pads. The longer the pad, the harder it is to break and the less often you use the same pad the better the security is.
hutch at movsd dot com
http://www.masm32.com

#### Farabi

• Member
• Posts: 969
• Neuroscience Fans
##### Re: Simple Encryption Algorithm
« Reply #6 on: November 25, 2015, 02:23:23 PM »
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

#### cman

• Member
• Posts: 222
##### Re: Simple Encryption Algorithm
« Reply #7 on: November 26, 2015, 08:11:29 AM »
Thanks for all your suggestions! I've been looking at the TEA ( tiny encryption algorithm ) to write into my project. I might try this algorithm as I think it might be fun to use something somewhat secure. The code is simple and I've even found an assembly language implementation: ( AT&T syntax  :( )  http://www.nayuki.io/page/tiny-encryption-algorithm-in-x86-assembly

#### jj2007

• Member
• Posts: 10546
• Assembler is fun ;-)
##### Re: Simple Encryption Algorithm
« Reply #8 on: November 26, 2015, 11:51:36 AM »
I've just hacked together an encrypter-decrypter pair based on Rand(). Sources and executables attached, usage should be straightforward: Extract all to a folder, then drag whatever file over Encrypt.exe

It is fast and secure as long as you don't just accept the suggested password ;)

"Secure" means it looks 100% random. Here is the ENT analysis of a combined Windows.inc + WinExtra.inc 2MB file:

Original:
Code: [Select]
`ent \masm32\include\combined.incEntropy = 4.678218 bits per byte.Optimum compression would reduce the sizeof this 2045966 byte file by 41 percent.Chi square distribution for 2045966 samples is 49984775.66, and randomlywould exceed this value less than 0.01 percent of the times.Arithmetic mean value of data bytes is 62.6084 (127.5 = random).Monte Carlo value for Pi is 4.000000000 (error 27.32 percent).Serial correlation coefficient is 0.581272 (totally uncorrelated = 0.0).`
Encrypted:
Code: [Select]
`ent combi.tmpEntropy = 7.999906 bits per byte.Optimum compression would reduce the sizeof this 2045972 byte file by 0 percent.Chi square distribution for 2045972 samples is 267.73, and randomlywould exceed this value 27.97 percent of the times.Arithmetic mean value of data bytes is 127.5636 (127.5 = random).Monte Carlo value for Pi is 3.141430226 (error 0.01 percent).Serial correlation coefficient is -0.000726 (totally uncorrelated = 0.0).`

#### K_F

• Member
• Posts: 1609
• Anybody out there?
##### Re: Simple Encryption Algorithm
« Reply #9 on: November 26, 2015, 05:32:28 PM »
This should tickle your fancy....  https://en.wikipedia.org/wiki/Enigma_machine
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

#### ragdog

• Member
• Posts: 610
##### Re: Simple Encryption Algorithm
« Reply #10 on: November 27, 2015, 05:24:03 AM »
Ohh lol Enigma

But for a tool to encrypt/decrypt messages or Files think i is it bad
Other good way is Rsa greater 512 better 1024

#### GoneFishing

• Member
• Posts: 1071
• Gone fishing
##### Re: Simple Encryption Algorithm
« Reply #11 on: November 27, 2015, 05:44:46 AM »
The simplest one : https://en.wikipedia.org/wiki/Caesar_cipher

Code: [Select]
`include \masm32\include\masm32rt.incVigenereTable MACRO     FORC char , <ABCDEFGHIJKLMNOPQRSTUVWXYZA>           pos INSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, <&char>           tmp\$ SUBSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ>,pos,26          %echo tmp\$    ENDMENDMDECRYPT MACRO Ciphertext, key    local cnt    cnt = 1     FORC char, <&Ciphertext>         keychar SUBSTR <&key>,cnt,1         pos   INSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZ>, keychar         line\$ SUBSTR <ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ>,pos,26         pos_1 INSTR line\$, <&char>         origChar SUBSTR  <ABCDEFGHIJKLMNOPQRSTUVWXYZ>,pos_1,1         %echo origChar        cnt =cnt+1    ENDMENDM .code        start:        VigenereTable         DECRYPT  LXFOPVEFRNHR, LEMONLEMONLE  .errend start`
OUTPUT:
Quote
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A
T
T
A
C
K
A
T
D
A
W
N

TESTED WITH JWASM
« Last Edit: November 27, 2015, 09:12:29 AM by GoneFishing »

#### GoneFishing

• Member
• Posts: 1071
• Gone fishing
##### Re: Simple Encryption Algorithm
« Reply #12 on: November 27, 2015, 09:37:16 AM »
DECIPHER ME:
Quote
FUWXU KHW HZO IKEQ LVIL EPX ZSCDWP YWGG
FMCEMY ZN FRWKEJA RVS LHMPQW NYJHKR
KHSV JXXE FHR QTCJEX JIO KKA EEIZTU
HINT:  Ex-Libris by Ross King

#### K_F

• Member
• Posts: 1609
• Anybody out there?
##### Re: Simple Encryption Algorithm
« Reply #13 on: November 27, 2015, 09:49:29 PM »
Ohh lol Enigma

But for a tool to encrypt/decrypt messages or Files think i is it bad
Other good way is Rsa greater 512 better 1024
Ahh!.. Enigma was cracked because the coding machine 'mechanics' was known..
For computer file encryption and transfer, the 'encoding machine' is unknown to the eaves-dropper.
RSA 256/1024 size styles could just as easily be made up of many more enigma wheels.
Each wheel's content and movement only known to the user, and these variables can be changed by code within the message.

It's simple to implement in asm, and can be very effective.
Every code is crackable.. even RSA has been cracked.

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

#### ragdog

• Member
• Posts: 610
##### Re: Simple Encryption Algorithm
« Reply #14 on: November 27, 2015, 11:41:07 PM »
Quote
even RSA has been cracked

Sure but Rsa is secure the last broken key is 768 but to factorize >768 it cost many time (years)

Quote
RSA-768

The effort took almost 2000 2.2GHz-Opteron-CPU years according to the submitters, just short of 3 years of calendar time.

I think by factor a key >768  say your Cpu (home pc) good night