June 28, 2024, 03:04:19 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Encryption routines

Started by Peter, April 29, 2008, 05:58:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter

I was just a little curious if there are a bunch of encryptionroutines out there converted for EBasic that we just haven't seen in the forums yet.
Feel free to add some here. We can never have too many encryptionroutines.

I needed a really tiny code to just hide data for the eye and nothing more.

for i = 0 to charcount-1
*<CHAR>(pString+i) = *<CHAR>(pString+i) || 6
next i

The code would simply xor the asciivalues with "6" which hides it enough to prevent someone from just looking at it and immediately understand what hides beneath.
To make this code more efficient, you could use a string that it would loop through instead of just using "6".

I have made a few attempts on writing assemblerimplementations of RC4, RC5 and RC6, but my knowledge in assembler only made me angry and thus the samples are no more.

pistol350

Here is an RC4 encryption example by Copex  :)


String teststring,ekey
teststring="Now is the time for all good men to come to the aid of IBasic."
ekey="My Secret Key"

Print teststring
Print ekey
Print
teststring=RC4(teststring,ekey)   :' Encrypt
Print "Encrypted String"
Color 15,0
Print teststring
Color 7,0
teststring=RC4(teststring,ekey)   :'Decrypt
Print
Print "UnEncrypted String"
Color 15,0
Print teststring
Print
Color 14,0
Print "Press any key"
Do:Until Inkey$<>""
 
Sub RC4(inp As String,key As String),String
   Dim S[255],K[255],temp,y As Char
   Dim i,j,t,x As Int
   Dim Outp[25000] As IString
   Outp=""
   For i=0 to 255
      S[i]=i
   Next i
   j=1
   For i=0 to 255
      If j>Len(key) Then j=1
      K[i]=Asc(Mid$(key,j,1))
      j++
   Next i
   j=0
   For i=0 to 255
      j=(j+S[i]+K[i])%256
      temp=S[i]
      S[i]=S[j]
      S[j]=temp
   Next i
   i=0
   j=0
   For x=1 to Len(inp)
      i=(i+1)%256
      j=(j+S[i])%256
      temp=S[i]
      S[i]=S[j]
      S[j]=temp
      t=(S[i]+(S[j]%256))%256
      Y=S[t]
      Outp+=Chr$(Asc(Mid$(inp,x,1))||Y)
   Next x
   Return Outp
EndSub
Regards,

Peter B.

pistol350

This one is a simple ASCII encryption by Splakidas   :)


/*
ascii encryption
by splakidas, 2006
ibasic pro code
*/

STRING text, key, encrypted, decrypted

text = "test text"
key = "secretkey"
encrypted = stpAsc(text, key, 1)
decrypted = stpAsc(encrypted, key, 0)

print "text:           ", text
print "encrypted text: ", encrypted
print "decrypted text: ", decrypted

do:until inkey$<>""
end

sub stpAsc(inlex:string, cods:string, eid:int), string
/*
inlex:string    incoming word for encrption
cods:string  password
eid:int         1=encrypt 0=decrypt
lexout          encrypted or decrypted word
*/
int co,val1,val2,val3
string lexout,lex1,lex2,lex3
lexout=""
for n=1 to len(inlex)

co++ : if co>len(cods) then co=1
cl=mid$(cods,co,1)

lex1=mid$(inlex,n,1)
lex2=cl

val1=asc(lex1)
val2=asc(lex2)
if eid=1 then
val3=val1 - val2 :if val3<1 then val3=val3+255
else
val3=val1 + val2 :if val3>255 then val3=val3-255
endif
lex3=chr$(val3)

lexout=lexout+lex3
next n

return lexout
ENDSUB
Regards,

Peter B.

Peter

Sweet examples. Am I misreading or is that RC4-implementation useless for binary strings containing chr$(0) etc?

Copex

Quote from: pistol350 on April 29, 2008, 08:58:13 AM
Here is an RC4 encryption example by Copex  :)


this was not coded by me, though i may have reposted it, it was posted on the IBpro fourms some time ago....
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

pistol350

Indeed,

it was written by SmOoth.
Regards,

Peter B.

Peter

Yeah, I know who wrote it originally. Was just asking since I was a bit unsure if I was correct.
Since none of the params are the length of the text being encrypted and there are only strings, I understand it wouldn't work on binary strings. Nice implementation otherwise.

Hope more people will paste their encryptions (or implementations of existing encryptionalgorithms).