# Simple encryption algorithm

## Recommended Posts

Since I do not remember any secure hashing or encryption algorithms in LUA, I made one myself, based on the idea of the blowfish algorithm (but less complicated).

```iaEncryptionArray = {};
caText = "";
caEncryptedText = "";

end
if (output > 999) then
output = output - 1000;
end
return output;
end

end
if (output < 0) then
output = output + 1000;
end
return output;
end

caOutput = "";
end
end
return caOutput;
end

function stringSetChar(string,char,pos)
length = string.len(string);
if pos > length then
return string;
end
string = string.sub(string,1,pos) .. char .. string.sub(string,pos+1,length);
return string;
end

function generateEncryptionArray()
generateDecryptionArray();
end

function generateDecryptionArray()
for i=0, 999, 1 do
iaEncryptionArray[i]=NIL;
end
iPosition = 0;
n=1;
for i=0, 999, 1 do
n = n + 1;
n=1;
end
iPosition = iPosition % 1000;
while (iaEncryptionArray[iPosition]) do
iPosition = iPosition + 1;
if (iPosition >= 1000) then
iPosition = iPosition - 1000;
end
end
iaEncryptionArray[iPosition] = i;
end
end

function encrypt()
generateEncryptionArray();
iTextSize = string.len(caText);
iEncryptedTextSize = iTextSize*3;
caEncryptedText = "";
aEncryptedText = {};
for i=1, iTextSize, 1 do
value = string.byte(caText,i);
n=i*3;
if (value < 10) then
value = string.format("00%i",value);
elseif (value < 100) then
value = string.format("0%i",value);
else
value = string.format("%i",value);
end
aEncryptedText[(i-1)*3+1] = string.byte(value,1) - 48;
aEncryptedText[(i-1)*3+2] = string.byte(value,2) - 48;
aEncryptedText[(i-1)*3+3] = string.byte(value,3) - 48;
end
for i=1,iEncryptedTextSize,1 do
caEncryptedText = caEncryptedText .. string.format("%i",aEncryptedText[i]);
end
for runs=1, 32, 1 do
for i=1, iEncryptedTextSize, 1 do
pos1 = i;
pos2 = i+1;
pos3 = i+2;
if (pos2 > iEncryptedTextSize) then
pos2 = pos2 - iEncryptedTextSize;
pos3 = pos3 - iEncryptedTextSize;
elseif (pos3 > iEncryptedTextSize) then
pos3 = pos3 - iEncryptedTextSize;
end
h = aEncryptedText[pos1];
z = aEncryptedText[pos2];
e = aEncryptedText[pos3];
value = 100*h + 10*z + e;
value = iaEncryptionArray[value];
h = math.floor(value / 100);
value = value - 100*h;
z = math.floor(value / 10);
value = value - 10*z;
e = value;
aEncryptedText[pos1] = h;
aEncryptedText[pos2] = z;
aEncryptedText[pos3] = e;
end
end
caEncryptedText = "";
for i=1,iEncryptedTextSize,1 do
caEncryptedText = caEncryptedText .. string.format("%i",aEncryptedText[i]);
end
end

function decrypt()
generateDecryptionArray();
iEncryptedTextSize = string.len(caEncryptedText);
aEncryptedText = {};
for i=1,iEncryptedTextSize,1 do
aEncryptedText[i] = string.byte(caEncryptedText,i) - 48;
end
caEncryptedText = "";
for runs=1, 32, 1 do
for i=iEncryptedTextSize, 1, -1 do
pos1 = i;
pos2 = i+1;
pos3 = i+2;
if (pos2 > iEncryptedTextSize) then
pos2 = pos2 - iEncryptedTextSize;
pos3 = pos3 - iEncryptedTextSize;
elseif (pos3 > iEncryptedTextSize) then
pos3 = pos3 - iEncryptedTextSize;
end
h = aEncryptedText[pos1];
z = aEncryptedText[pos2];
e = aEncryptedText[pos3];
value = 100*h + 10*z + e;
h = math.floor(value / 100);
value = value - 100*h;
z = math.floor(value / 10);
value = value - 10*z;
e = value;
aEncryptedText[pos1] = h;
aEncryptedText[pos2] = z;
aEncryptedText[pos3] = e;
end
end
iTextSize = iEncryptedTextSize / 3
caText = "";
for i=1,iEncryptedTextSize,1 do
caEncryptedText = caEncryptedText .. string.format("%i",aEncryptedText[i]);
end
for i=1, iTextSize, 1 do
n = (i-1)*3+1;
char = aEncryptedText[n]*100 + aEncryptedText[n+1]*10 + aEncryptedText[n+2];
if char > 255 then
return;
end
caText = caText .. string.char(char);
end
end

caText = caTextInput;
encrypt();
return (caEncryptedText);
end

caEncryptedText = caTextInput;
decrypt();
return (caText);
end

print(plaintext);
```

The only problem about it is that the output is three times larger then the input, since I found no way of doing a bitwise operations in LUA.

Using this algorithm i encrypted:

A simple LUA encryption

to:

888953271697817971988875429150003339473916115385183229145025698478333

and

123 test

to

589213431067573308035761

and

1234567890

to

599957627210660816794255945607

and

abcdefghijklmnopqrstuvwxyz

to

363695469390506373834224316510624908352602626076666225352477454426305393478617

The password is 7 chars long.

The algorithm is known, the plain text is known, if you are able to find out the password, I consider this algorithm to be a failure.

is md5 not good enough? for dp2.3 i'm pretty sure there was a module, and for 1.0 there are functions built into MTA.

is md5 not good enough? for dp2.3 i'm pretty sure there was a module, and for 1.0 there are functions built into MTA.

MD5 is not an encryption algorithm.

Also, I just did it. There was no reason for doing it except doing it.

So where's this encrypted version of the 7 char length password, that you want us to decrypt?

So where's this encrypted version of the 7 char length password, that you want us to decrypt?

with that secret password i encrypted:

A simple LUA encryption

to:

888953271697817971988875429150003339473916115385183229145025698478333

and

123 test

to

589213431067573308035761

and

1234567890

to

599957627210660816794255945607

and

abcdefghijklmnopqrstuvwxyz

to

363695469390506373834224316510624908352602626076666225352477454426305393478617

I just want you to BREAK the algorithm.

All of these lines use the same password.

If you want to encrypt/decrypt something yourself, be sure to use ASCII text and an ASCII password.

I tested it with random text several times.

When you find out the password (which is 7 chars in size), my algorithm fails (plain text attack).

Imagining storing data client side and having the client find out the decryption password, i.e. by saving its position at a specified place!

I know the password by heart, so, if you want me to encrypt MOAR, then I'll do it.

I also have this algorithm in C, so, if you want to have the sourcecode for that, I should be able to provide it (even though i changed some things in the LUA sourcecode, i.e. adding the password in every step of the encryption).

Edit:

I found out there may be a bug.

The reason is the "iPasswordPosition" integer.

This bug should be solved easily.

Edit2:

Even though there is a "bug", it works, and I have no idea why.

iPasswordPosition is set to 1 every time.

Then, it is increased.

Why the hack does it decrypt the same way it encrypts and still work?

Sorry for double posting, sorry for failing so hard:

I made a mistake in the implementation.

```
iaEncryptionArray = {};
caText = "";
caEncryptedText = "";

end
if (output > 999) then
output = output - 1000;
end
return output;
end

end
if (output < 0) then
output = output + 1000;
end
return output;
end

caOutput = "";
end
end
return caOutput;
end

function stringSetChar(string,char,pos)
length = string.len(string);
if pos > length then
return string;
end
string = string.sub(string,1,pos) .. char .. string.sub(string,pos+1,length);
return string;
end

function generateEncryptionArray()
generateDecryptionArray();
end

function generateDecryptionArray()
for i=0, 999, 1 do
iaEncryptionArray[i]=NIL;
end
iPosition = 0;
n=1;
for i=0, 999, 1 do
n = n + 1;
n=1;
end
iPosition = iPosition % 1000;
while (iaEncryptionArray[iPosition]) do
iPosition = iPosition + 1;
if (iPosition >= 1000) then
iPosition = iPosition - 1000;
end
end
iaEncryptionArray[iPosition] = i;
end
end

function encrypt()
generateEncryptionArray();
iTextSize = string.len(caText);
iEncryptedTextSize = iTextSize*3;
caEncryptedText = "";
aEncryptedText = {};
for i=1, iTextSize, 1 do
value = string.byte(caText,i);
n=i*3;
if (value < 10) then
value = string.format("00%i",value);
elseif (value < 100) then
value = string.format("0%i",value);
else
value = string.format("%i",value);
end
aEncryptedText[(i-1)*3+1] = string.byte(value,1) - 48;
aEncryptedText[(i-1)*3+2] = string.byte(value,2) - 48;
aEncryptedText[(i-1)*3+3] = string.byte(value,3) - 48;
end
iCounter = 1;
for runs=1, 32, 1 do
for i=1, iEncryptedTextSize, 1 do
iCounter = iCounter + 1;
pos1 = i;
pos2 = i+1;
pos3 = i+2;
if (pos2 > iEncryptedTextSize) then
pos2 = pos2 - iEncryptedTextSize;
pos3 = pos3 - iEncryptedTextSize;
elseif (pos3 > iEncryptedTextSize) then
pos3 = pos3 - iEncryptedTextSize;
end
h = aEncryptedText[pos1];
z = aEncryptedText[pos2];
e = aEncryptedText[pos3];
value = 100*h + 10*z + e;
value = iaEncryptionArray[value];
h = math.floor(value / 100);
value = value - 100*h;
z = math.floor(value / 10);
value = value - 10*z;
e = value;
aEncryptedText[pos1] = h;
aEncryptedText[pos2] = z;
aEncryptedText[pos3] = e;
end
end
caEncryptedText = "";
for i=1,iEncryptedTextSize,1 do
caEncryptedText = caEncryptedText .. string.format("%i",aEncryptedText[i]);
end
end

function decrypt()
generateDecryptionArray();
iEncryptedTextSize = string.len(caEncryptedText);
aEncryptedText = {};
for i=1,iEncryptedTextSize,1 do
aEncryptedText[i] = string.byte(caEncryptedText,i) - 48;
end
caEncryptedText = "";
iPasswordPosition = - (iEncryptedTextSize*32) - 1;
for runs=1, 32, 1 do
for i=iEncryptedTextSize, 1, -1 do
pos1 = i;
pos2 = i+1;
pos3 = i+2;
if (pos2 > iEncryptedTextSize) then
pos2 = pos2 - iEncryptedTextSize;
pos3 = pos3 - iEncryptedTextSize;
elseif (pos3 > iEncryptedTextSize) then
pos3 = pos3 - iEncryptedTextSize;
end
h = aEncryptedText[pos1];
z = aEncryptedText[pos2];
e = aEncryptedText[pos3];
value = 100*h + 10*z + e;
h = math.floor(value / 100);
value = value - 100*h;
z = math.floor(value / 10);
value = value - 10*z;
e = value;
aEncryptedText[pos1] = h;
aEncryptedText[pos2] = z;
aEncryptedText[pos3] = e;
end
end
iTextSize = iEncryptedTextSize / 3
caText = "";
for i=1,iEncryptedTextSize,1 do
caEncryptedText = caEncryptedText .. string.format("%i",aEncryptedText[i]);
end
for i=1, iTextSize, 1 do
n = (i-1)*3+1;
char = aEncryptedText[n]*100 + aEncryptedText[n+1]*10 + aEncryptedText[n+2];
if char > 255 then
return;
end
caText = caText .. string.char(char);
end
end

if caTextInput == nil or caPasswordInput == nil then
return nil;
end
caText = caTextInput;
encrypt();
return (caEncryptedText);
end

if caTextInput == nil or caPasswordInput == nil then
return nil;
end
caEncryptedText = caTextInput;
decrypt();
return (caText);
end

```

The string:

A simple LUA encryption

Was encrypted to:

682119734823703509077954997710015337233693472802500191840149774364729

The string:

1234567890

Was encrypted to:

933712879701133814501918158559

The string:

abcdefghijklmnopqrstuvwxyz

Was encrypted to:

530526185999974651768906379994835597147588329912489932067818658885112960517611

The string:

TEST

Was encrypted to:

627098568592

The string:

one

Was encrypted to:

454931977

## Create an account

Register a new account