Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encryption/Decryption functions
#1
Some time ago I made an encryption engine for my FOS (Fake OS, a GUI)

The FOS which I named Novix uses its own Fake FAT system (based upon DOS)

All data that is stored will be encrypted so is all the data sent betveen programs (Novix uses a built in script engine) running in Novix.

My Encrypter/Decrypter works fine, but it is somewhat based on RND wich can only generate a set amout of random numbers

The password used when using the engine in Novix is 512+ chars long, so repetition is not the issue when it comes to password lenght, in the example though feel free to try anything.
Code:
DEFINT A-Z
'$DYNAMIC
DECLARE FUNCTION Decode$ (in$, pass$)
DECLARE FUNCTION Encode$ (in$, pass$)

RANDOMIZE TIMER

CLS

'note same string and password in all 3 cases
Coded$ = Encode$("Hello, World", "password here")
PRINT Coded$
PRINT Decode$(Coded$, "password here")

'note same string and password in all 3 cases
Coded$ = Encode$("Hello, World", "password here")
PRINT Coded$
PRINT Decode$(Coded$, "password here")

'note same string and password in all 3 cases
Coded$ = Encode$("Hello, World", "password here")
PRINT Coded$
PRINT Decode$(Coded$, "password here")

FUNCTION Decode$ (in$, pass$)
oin$ = in$
IF LEN(in$) < 2 THEN EXIT FUNCTION
t! = LEN(in$) / 2
m = INT(LEN(in$) / 2)
IF m = t! THEN
d1$ = LEFT$(in$, m - 1)
d2$ = RIGHT$(in$, m)
m$ = MID$(in$, m, 1)
ELSE
d1$ = LEFT$(in$, m)
d2$ = RIGHT$(in$, m)
m$ = MID$(in$, m + 1, 1)
END IF
in$ = d1$ + d2$
g = ASC(m$)
FOR a = 1 TO LEN(in$)
pl = pl + 1
IF pl > LEN(pass$) THEN pl = 1: q = q + 1
b = ASC(MID$(in$, a, 1))
IF g > 127 THEN
  c = ASC(MID$(pass$, LEN(pass$) - (pl - 1), 1))
ELSE
  c = ASC(MID$(pass$, pl, 1))
END IF
bc = b - c - g - a - pl - q
DO
  IF bc < 0 THEN bc = bc + 255
LOOP WHILE bc < 0
d$ = d$ + CHR$(bc)
NEXT
Decode$ = d$
in$ = oin$
END FUNCTION

FUNCTION Encode$ (in$, pass$)
g = (255 * RND + 255 * RND) * RND
IF g > 255 THEN g = g - 255
FOR a = 1 TO LEN(in$)
pl = pl + 1
IF pl > LEN(pass$) THEN pl = 1: q = q + 1
b = ASC(MID$(in$, a, 1))
IF g > 127 THEN
  c = ASC(MID$(pass$, LEN(pass$) - (pl - 1), 1))
ELSE
  c = ASC(MID$(pass$, pl, 1))
END IF
bc = b + c + g + a + pl + q
DO
  IF bc > 255 THEN bc = bc - 255
LOOP WHILE bc > 255
c$ = CHR$(VAL("&H" + HEX$(bc)))
d$ = d$ + c$
NEXT
g$ = CHR$(VAL("&H" + HEX$(g)))
t! = LEN(d$) / 2
m = INT(LEN(d$) / 2)
IF m = t! THEN
p1$ = LEFT$(d$, m)
p2$ = RIGHT$(d$, m)
d$ = p1$ + g$ + p2$
ELSE
p1$ = LEFT$(d$, m)
p2$ = RIGHT$(d$, m + 1)
d$ = p1$ + g$ + p2$
END IF
Encode$ = d$
END FUNCTION

Do not comment on the [...]code instead of [...]crypt I was young and foolish :wink:

So now, do everything you can to ruin my life by saying my encrypter suck (and give a reason)

Also note that the encrypted string may (and most likely will) contain ascii chars below 31, so expect char 13 and so on to show their face Tongue
Reply
#2
Thats quite a nice code. The encryption algo is looking good. Quite difficult to crack( for me ) Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)