As usual, this is a Module version of the original code. My question is : How to make it Unicode Compliant ?
Best regards
StarBootics
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : RollingEncryption - Module
; File Name : RollingEncryption - Module.pb
; File version: 1.1.0
; Programming : OK
; Programmed by : StarBootics
; Date : 09-04-2016
; Last Update : 09-04-2016
; PureBasic code : V5.42 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; This code was originally created by Bo Marchais
;
; I deserve credit only to convert the original
; code into a Module.
;
; This code is free to be use where ever you like
; but you use it at your own risk.
;
; The author can in no way be held responsible
; for data loss, damage or other annoying
; situations that may occur.
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DeclareModule RollingEncryption
Declare Initialize(P_Salt.u)
Declare Reset()
Declare.s Encode(P_String.s)
Declare.s Decode(P_String.s)
EndDeclareModule
Module RollingEncryption
Structure Instance
IsInitialize.b
Salt.u
EndStructure
Global Instance.Instance
Procedure Initialize(P_Salt.u)
Instance\IsInitialize = #True
Instance\Salt = P_Salt
EndProcedure
Procedure Reset()
Instance\IsInitialize = 0
Instance\Salt = 0
EndProcedure
Procedure.s Encode(P_String.s)
If Instance\IsInitialize = #True
For i = 1 To Len(P_String)
encoded.s + Right("0000" + Hex(Asc(Mid(P_String,i,1)) ! ((Instance\Salt + i) % 65535), #PB_Unicode), 4)
Next
EndIf
ProcedureReturn UCase(encoded)
EndProcedure
Procedure.s Decode(P_String.s)
If Instance\IsInitialize = #True
For i = 1 To (Len(P_String)/4)
ptr = ((i - 1) * 4) + 1
decoded.s + Chr(Val("$"+Mid(P_String, ptr, 4)) ! ((Instance\Salt + i) % 65535))
Next
EndIf
ProcedureReturn decoded
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
RollingEncryption::Initialize(65342)
input$ = "It might be useful..."
Encoded$ = RollingEncryption::Encode(input$)
Decoded$ = RollingEncryption::Decode(Encoded$)
Debug "SOURCE: " + input$
Debug "CIPHER: " + Encoded$
Debug "OUTPUT: " + Decoded$
RollingEncryption::Reset()
CompilerEndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<