Read Write XOR Encoded String - V2.0.0
Posted: Sun Jun 12, 2011 2:33 am
Hello everyone,
Just a tiny XOR Encoded lib. This tiny lib just don't deserve a Nobel price.
Have fun !
Best regards.
Guimauve
Just a tiny XOR Encoded lib. This tiny lib just don't deserve a Nobel price.
Have fun !
Best regards.
Guimauve
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project Name : Read/Write XOR Encoded String
; File Name : Read Write XOR Encoded String.pb
; File version: 1.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 11-06-2011
; Update : 11-06-2011
; PureBasic code : 4.60 Beta 3
; Plateform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Macro Looping(P_Number, P_Minimum, P_Maximum)
P_Number = P_Number + 1
If P_Number > P_Maximum
P_Number = P_Minimum
EndIf
EndMacro
Procedure.s XOREncodeString(Key.s, Text.s)
KeyLength = Len(Key)
TextLength = Len(Text)
For Index = 1 To TextLength
Looping(KeyIndex, 1, KeyLength)
Encoded.s = Encoded + Chr(Asc(Mid(Text, Index, 1)) ! ~Asc(Mid(Key, KeyIndex, 1)))
Next
ProcedureReturn Encoded
EndProcedure
Procedure WriteXOREncodedString(FileID.l, Key.s, Text.s)
KeyLength = Len(Key)
TextLength = Len(Text)
WriteLong(FileID, TextLength)
For Index = 1 To TextLength
Looping(KeyIndex, 1, KeyLength)
WriteCharacter(FileID, Asc(Mid(Text, Index, 1)) ! ~Asc(Mid(Key, KeyIndex, 1)))
Next
EndProcedure
Procedure.s ReadXOREncodedString(FileID.l, Key.s)
KeyLength = Len(Key)
TextLength = ReadLong(FileID)
For Index = 1 To TextLength
Looping(KeyIndex, 1, KeyLength)
Encoded.s = Encoded + Chr(ReadCharacter(FileID) ! ~Asc(Mid(Key, KeyIndex, 1)))
Next
ProcedureReturn Encoded
EndProcedure
Key.s = "PureBasic 4.60 Beta 3"
Text.s = "I like the super sexy Nordic goddesses !"
Encoded.s = XOREncodeString(Key, Text)
Decoded.s = XOREncodeString(Key, Encoded)
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Straight String Test"
Debug ""
Debug Text
Debug Encoded
Debug Decoded
Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Binary File Test"
Debug "Original : " + Text
If CreateFile(0, "Test.Enc")
WriteXOREncodedString(0, Key, Text)
CloseFile(0)
EndIf
If ReadFile(1, "Test.Enc")
Debug "From file : " + ReadXOREncodedString(1, Key)
CloseFile(1)
DeleteFile("Test.Enc")
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<