...
Publié : mer. 25/août/2004 23:55
...
Code : Tout sélectionner
Procedure XorWithKey (sText.l, LenText.l, sKey.l, LenKey.l)
! XOR ecx, ecx
! MOV esi, dword [esp]
! MOV edi, dword [esp+8]
! MOV edx, dword [esp+4]
! MOV ebp, dword [esp+12]
! ADD ebp, esi
! _xornextbyte:
! MOV al, [esi]
! MOV bl, [edi]
! XOR al, bl
! MOV [esi], al
! INC ecx
! INC esi
! INC edi
! CMP esi, ebp
! JGE _xorcomplete
! CMP ecx, edx
! JGE _xornextround
! JMP _xornextbyte
! _xornextround:
! XOR ecx, ecx
! SUB edi, edx
! JMP _xornextbyte
! _xorcomplete:
EndProcedure
Procedure XorWithKeyPBCode(sText.l, LenText.l, sKey.l, LenKey.l)
LenKey + sText
Repeat
For i = 0 To LenKey
PokeB(sText, PeekB(sText) ! PeekB(sKey))
sText + 1
sKey + 1
If sText => LenKey : Goto XorWithKeyPBCodecomplete : EndIf
Next
sKey - LenText
ForEver
XorWithKeyPBCodecomplete:
EndProcedure
Procedure XorWithKeyASMCode(sText.l, LenText.l, sKey.l, LenKey.l)
! MOV eax, dword [esp+12] ; LenKey + sText
! ADD eax, dword [esp]
! _XorWithKeyASMCode_Repeat: ; Repeat
! MOV ebx, 0 ; i = 0 ; For i = 0 To LenKey
! _XorWithKeyASMCode_For_i:
! MOV ecx, dword [esp] ; PokeB(sText, PeekB(sText) ! PeekB(sKey))
! MOV edx, dword [esp+8]
! MOV esi, [ecx]
! XOR esi, [edx]
! MOV [ecx], esi
! INC ecx ; sText + 1
! INC edx ; sKey + 1
! CMP ecx, dword [esp+12] ; If sText => LenKey : Goto XorWithKeyASMCodecomplete : EndIf
! JGE _XorWithKeyASMCodecomplete
! INC ebx ; i + 1 ; Next
! CMP ebx, dword [esp+12] ; If i <= LenKey : Goto XorWithKeyASMCode_For_i : EndIf
! JGE _XorWithKeyASMCode_For_i
! SUB edx, dword [esp+4] ; sKey - LenText
! JMP _XorWithKeyASMCode_Repeat ; Goto XorWithKeyASMCode_Repeat
! _XorWithKeyASMCodecomplete:
EndProcedure
sText.s = "PureBasic est super."
sKey.s = "azertyuiop"
Debug sText
;// Encrypt
XorWithKey(@sText, Len(sText), @sKey, Len(sKey))
;// And again, which decrypts it
Debug sText
XorWithKey(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
sText.s = "PureBasic est super."
sKey.s = "azertyuiop"
XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
sText.s = "Voyez le brick géant que j'examine près du wharf"
sKey.s = "azertyuiop"
XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
sText.s = "PureBasic est super."
sKey.s = "azertyuiop"
XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
sText.s = "Voyez le brick géant que j'examine près du wharf"
sKey.s = "azertyuiop"
XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
Count = 100000
tz = ElapsedMilliseconds() : For i = 1 To Count : sText.s = "PureBasic est super." : sKey.s = "azertyuiop" : XorWithKey(@sText, Len(sText), @sKey, Len(sKey)) : XorWithKey(@sText, Len(sText), @sKey, Len(sKey)) : Next : Debug ElapsedMilliseconds() - tz
tz = ElapsedMilliseconds() : For i = 1 To Count : sText.s = "PureBasic est super." : sKey.s = "azertyuiop" : XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey)) : XorWithKeyPBCode(@sText, Len(sText), @sKey, Len(sKey)) : Next : Debug ElapsedMilliseconds() - tz
tz = ElapsedMilliseconds() : For i = 1 To Count : sText.s = "PureBasic est super." : sKey.s = "azertyuiop" : XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey)) : XorWithKeyASMCode(@sText, Len(sText), @sKey, Len(sKey)) : Next : Debug ElapsedMilliseconds() - tz
Code : Tout sélectionner
sText.s = "Voyez le brick géant que j'examine près du wharf"
sKey.s = "PureBasic est super."
XorWithKey(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
XorWithKey(@sText, Len(sText), @sKey, Len(sKey))
Debug sText
Code : Tout sélectionner
sText.s = "Voyez le brick géant que j'examine près du wharf"
sKey.s = "PureBasic est super."
lText = Len(sText)
XorWithKey(@sText, lText, @sKey, Len(sKey))
Debug sText
XorWithKey(@sText, lText, @sKey, Len(sKey))
Debug sText