Code archives/Algorithms/small encryption algorithm for ints

This code has been declared by its author to be Public Domain code.

Download source code

small encryption algorithm for ints by Nate the Great2010
well I made this algorithm up recently then discovered it was already invented a while ago... anyway here it is working with integers. You can have a key as long as you like which is a definite plus :)
'make a file in notepad or whatever you like and call it myfile.bla and type in some random stuff... then this will encrypt/decrypt it

rs:TStream = ReadFile("myfile.bla")
ws:TStream = WriteFile("myfileencrypted.bla")
encrypt(rs,ws,"12340987437643987234")
CloseStream rs
CloseStream ws

rs:TStream = ReadFile("myfileencrypted.bla")
Print "now lets encrypt it!"
While Not Eof(rs)
	Print ReadByte(rs)
Wend
CloseStream rs

rs:TStream = ReadFile("myfileencrypted.bla")
ws:TStream = WriteFile("myfiledecrypted.bla")
decrypt(rs,ws,"12340987437643987234")
CloseStream rs
CloseStream ws

Print "now lets decrypt it!"
rs:TStream = ReadFile("myfiledecrypted.bla")
While Not Eof(rs)
	Print ReadByte(rs)
Wend
CloseStream rs

Function Encrypt(rstream:TStream,wstream:TStream,key:String)	'the key is a set of numbers any length... "432197843" or "324" or "3244325"

	Local cnt:Int
	Local n:Byte
	Local leng:Int = Len(key)
	While Not Eof(rstream)	
		n = (ReadByte(rstream) + Int(Mid(key,(cnt Mod leng)+1,1)))
		WriteByte(wstream,n)
		cnt:+1
	Wend
End Function

Function Decrypt(rstream:TStream,wstream:TStream,key:String)

	Local cnt:Int
	Local n:Byte
	Local leng:Int = Len(key)
	While Not Eof(rstream)	
		n = (ReadByte(rstream) - Int(Mid(key,(cnt Mod leng)+1,1)))		'the only difference in these functions is the minus sign...
		WriteByte(wstream,n)
		cnt:+1
	Wend
End Function

Comments

Nate the Great2010
edit: fixed to work for strings or whatever... any type of file!!!


Code Archives Forum