Besoin de conseils pour fignoler mon crypteur
Publié : jeu. 17/mars/2016 18:24
Lut tous !!
J'ai fais un crypteur/decrypteur et je cherche a faire la carrosserie de ma procedure. Il crypte/decrypte selon la valeur de "CRYPT".
J'ai regardé la doc pour faire du canvas mais j'ai pas compris :
J'ai fais un crypteur/decrypteur et je cherche a faire la carrosserie de ma procedure. Il crypte/decrypte selon la valeur de "CRYPT".
J'ai regardé la doc pour faire du canvas mais j'ai pas compris :
Code : Tout sélectionner
UseMD5Fingerprint()
;Beep_(1500,150)
; --- reserve de nombres aleatoires ---
Dim r.q(1000)
For i=0 To 1000
cmb=Random(40)
For u=0 To cmb
r(i)+ Random(65536*32768-1)
; Debug r(i)
Next
;Debug("---")
Next
new=0
;Beep_(1500,150)
Beep_(500,150)
debut:
b.b=0
mdp$="SPH2016"
; c'est ici que se decide si on crypte ou on decrypte :
; 0 = crypter
; 1 = decrypter
crypt=0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If crypt=0
a$="crypter"
Else
a$="décrypter"
EndIf
Fichier$ = OpenFileRequester("Choisissez un fichier à "+a$, "*.*", "*.*", 0)
;Fichier$ = "c:\HexaScrabble2\HexaScrabble.exe"
If Fichier$
ReadFile(0, Fichier$)
;b.b=ReadByte(0)
;Debug b
Fichier2$ = OpenFileRequester("Choisissez un fichier à sauvegarder", "*.*", "*.*", 0)
If Fichier2$ And Fichier$<>Fichier2$
CreateFile(1, Fichier2$)
;-------------stockage des bits--------------
len=Len(mdp$)
Dim bit.b(len*8)
For i=1 To len
a$=Mid(mdp$,i,1)
For u=0 To 7
bit((i-1)*8+u+1) = (Asc(a$)>>u)%2
;Debug bit((i-1)*8+u+1)
Next
Next
;---calcul de total---
x.q=1
total.q=0
For i=1 To Len(mdp$)
mid$=Mid(mdp$,i,1)
total+Asc(mid$)*x
If x>=65536*65536*65536
x=1
Else
x*2
EndIf
Next
Debug total
;------------------calcul de md5$ et de md5--------------------
md5$= StringFingerprint(mdp$, #PB_Cipher_MD5)
Debug md5$
md5=0
For i=1 To Len(md5$)
mid$=Mid(md5$,i,1)
md5+Asc(mid$)
Next
Debug md5
;-------------------creation de dim octet et du premier octet-------------------
Dim octet.b(600)
If crypt=0
For i=0 To 600
octet(i)=Random(255)+Random(255)+Random(256)+Random(254)+Random(250)+Random(260)
Next
Else
For i=0 To 9
octet(i)=ReadByte(0)
Next
EndIf
bit4.b=total+md5+octet(0)+octet(1)+octet(2)+octet(3)+octet(4)+octet(5)+octet(6)+octet(7)+octet(8)+octet(9)
Debug bit4
bit4w.w=10+bit4&%00001111
Debug bit4w
octet(bit4w)=bit4
;--------------------
mdp_2=0
md5_2=0
tot_2=0
tot2_2=0
tot3_2=0
For u=1 To 32
md5$+ StringFingerprint(mdp$+Str(bit4), #PB_Cipher_MD5)
Debug md5$
md5=0
For i=1 To Len(md5$)
mid$=Mid(md5$,i,1)
md5+Asc(mid$)
Next
Debug md5
bit4.b=total+md5
Debug bit4
bit4w.w+1+bit4&%00001111
Debug bit4w
If u<=10
mdp_2+bit4w
EndIf
If u<=21
md5_2+bit4w
EndIf
If u<=32
tot_2+bit4w
EndIf
If u<=24
tot2_2+bit4w
EndIf
If u>=22
tot3_2+bit4w
EndIf
octet(bit4w)=bit4
Next
;--------------------
If crypt=0
Debug "===="
For i=0 To bit4w
b.b=octet(i)
;Debug b
WriteByte(1,b)
Next
Else
If Lof(0)>=bit4w+1
FileSeek(0, bit4w+1)
Else
MessageRequester("Information","Fichier trop petit !")
Goto fin
EndIf
EndIf
TempsDepart = ElapsedMilliseconds()
;mdp$, total, md5$, octet(), bit()
RandomSeed(total)
len*8
len2=1
While Eof(0) = 0
b.b=ReadByte(0)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
If bit(len2)=0
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
b=b!Random(255)
EndIf
While mdp_2>Len(mdp$)
mdp_2-Len(mdp$)
Wend
a$=Mid(mdp$,mdp_2,1)
b=b!Asc(a$)
deca2=Asc(a$)&%00000011
mdp_2+1
While md5_2>Len(md5$)
md5_2-Len(md5$)
Wend
a$=Mid(md5$,md5_2,1)
b=b!Asc(a$)
deca=Asc(a$)&%00000011
md5_2+1
While tot_2>Len(Str(total))
tot_2-Len(Str(total))
Wend
a$=Mid(Str(total),tot_2,1)
b=b!Asc(a$)
tot_2+1
While tot2_2>Len(mdp$)
tot2_2-Len(mdp$)
Wend
a$=Mid(mdp$,tot2_2,1)
b=b!(Asc(a$)<<deca)
tot2_2+1
While tot3_2>Len(md5$)
tot3_2-Len(md5$)
Wend
a$=Mid(md5$,tot3_2,1)
b=b!(Asc(a$)<<deca2)
tot3_2+1
; -------------------- bit de poids fort
b!(bit(len2)*128)
len2+1
If len2>len
len2=1
EndIf
WriteByte(1,b)
Wend
fin:
CloseFile(0)
CloseFile(1)
RandomSeed(r(new))
new+1
TempsEcoule = ElapsedMilliseconds()-TempsDepart
Debug "Temps écoulé : "+Str(TempsEcoule)+" millisecondes"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;fin;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Else
MessageRequester("Information","Impossible d'ouvrir le fichier!")
End
EndIf
EndIf
For i=1 To 3
Beep_(1500,90)
Delay(50)
Next
MessageRequester("Information","Temps écoulé : "+Str(TempsEcoule)+" millisecondes")
End
Goto debut