Tout sur la programmation
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Tout sur la programmation

programmation de tous les languages
 
AccueilPortailRechercherDernières imagesS'enregistrerConnexion
-39%
Le deal à ne pas rater :
Pack Home Cinéma Magnat Monitor : Ampli DENON AVR-X2800H, Enceinte ...
1190 € 1950 €
Voir le deal

 

 cryptage et décryptage

Aller en bas 
3 participants
AuteurMessage
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: cryptage et décryptage   cryptage et décryptage EmptySam 20 Aoû - 6:08

Bonjour.
Mon projet actuel est de créer un prgm de cryptage de données.
On rentre une phrase et une clé (autant de caractère qu'on veut) et le prgm crée une nouvelle phrase incompréhensible qu'on ne peut décripter qu'avec la clé.

Version actuelle

Code:
'***************************************************
'* CRYPTAGE v:2.2                                  *
'*                                                *
'* Created by Black Templar Août 2005              *
'*                                                *
'* programme permettant de crypter, décrypter et  *
'* enregistrer des données en format ".txt"        *
'*                                                *
'* OPEN SOURCE                                    *
'***************************************************
nomainwin
dim tx$(5)
WindowHeight = 275
WindowWidth = 230
UpperLeftX = 100
UpperLeftY = 50
menu #1, "&Fichier", "Nouveau", [new], "Ouvrir", [ouvrir], "Enregistrer", [enr], "Quitter", [quit]
radiobutton #1.rc, "Crypter", [crypter], [wait], 10, 10, 50, 20
radiobutton #1.rd, "Décrypter", [décrypter], [wait], 70, 10, 70, 20
statictext #1, "Clé :", 10, 40, 50, 20
statictext #1, "Texte :", 10, 70, 50, 20
statictext #1, "Résultat :", 10, 130, 50, 20
textbox #1.clé, 60, 40, 150, 20
textbox #1.txt, 60,70, 150, 20
button #1.cr, "Crypter", [cr], UL, 10, 100, 100, 20
button #1.dy, "Décrypter", [dy], UL, 110, 100, 100, 20
texteditor #1.txedit, 60, 130, 150, 80
open "crypter v: 2.1" for Window as #1
print #1, "trapclose [quit]"
#1.cr, "!hide"
#1.dy, "!hide"
call NoEdit
wait

[crypter]
#1.dy, "!hide"
#1.cr, "!show"
wait

[décrypter]
#1.cr, "!hide"
#1.dy, "!show"
wait

'code pour décrypter (inverse du cryptage)
[dy]
print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) - cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtdé$ = ""

for z = 1 to ch
    if lcr(z) < 33 then lcr(z) = lcr(z) + 92
    if chr$(lcr(z)) = "|" then
        txtdé$ = txtdé$ + " "
    else
        txtdé$ = txtdé$ + chr$(lcr(z))
    end if
next

txtcr$ = ""
print txtdé$
tx$(1) = txtdé$
goto [result]
wait

'code pour crypter
[cr]

print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
for z = 1 to ch
    'crypte avec les caractères couramment utilisé au clavier
    if lcr(z) > 126 then lcr(z) = lcr(z) - 92
    txtcr$ = txtcr$ + chr$(lcr(z))
next

'affiche la réponse
txtdé$ = ""
print txtcr$
tx$(1) = txtcr$
goto [result]
wait

[quit]
close #1
end

[wait]
wait

'********** Enregistrement **********
[enr]
nom$ = ""
filedialog "Save as...", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
wait
end if
if txtcr$ = "" then
notice "Il n'y a rien à enregistrer !"
wait
end if
if right$(nom$, 4) <> ".txt" then
    nom$ = nom$ + ".txt"
end if
open nom$ for output as #enregistrer
print #enregistrer, txtcr$
print #1.txt, ""
print #1.clé, ""
print #1.txedit, "!cls"
close #enregistrer
wait

'********** Ouvrir un fichier **********
[ouvrir]
nom$ = ""
filedialog "Ouvrir :", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
wait
end if
if right$(nom$, 4) <> ".txt" then
notice "Vous devez selectionner un fichier texte !"
wait
end if
open nom$ for input as #ouvrir
line input #ouvrir, drc$
print #1.txt, drc$
print #1.clé, ""
print #1.txedit, "!cls"
close #ouvrir
wait

[new]
print #1.clé, ""
print #1.txt, ""
print #1.txedit, "!cls"
txtcr$ = ""
txtdy$ = ""
wait

'********** Affiche le résultat dans Texteditor **********
[result]
if len(tx$(1)) > 105 then
notice "Vous ne pouvez pas dépacer 105 caractère !"
wait
end if
print #1.txedit, "!cls"
a = 1
while len(tx$(1)) > 21
a = a + 1
tx$(a) = left$(tx$(1), 21)
tx$(1) = right$(tx$(1), len(tx$(1)) - 21)
wend
for z = 2 to a
print #1.txedit, tx$(z)
next
print #1.txedit, tx$(1)
wait


'********** Efface le menu "edit" **********
Sub NoEdit
    hMain=hWnd(#1)
    hMainMenu=GetMenu(hMain)
    hMainEdit=GetSubMenu(hMainMenu,1)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#1)
    End Sub

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As long, r As boolean
    End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As long, nPos As long,_
    GetSubMenu As long
    End Function

Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As long,_
    GetMenu As long
    End Function

Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As long,_
    hSubMenu As long, _MF_BYCOMMAND As long,_
    RemoveMenu As boolean
    End Function

Développement, question réaction

Voici la version de base cryptage simple.

(Ne vous inquitez pas, il y aura une interface utilisateur pas la suite)
Code:
input "clé: "; clé$
input "txt: "; ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    if cl > len(clé$) then cl = 1
next

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
txtcr$ = ""
for z = 1 to ch
    if lcr(z) > 255 then lcr(z) = lcr(z) - 222
    txtcr$ = txtcr$ + chr$(lcr(z))
next

print txtcr$
Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptySam 20 Aoû - 11:58

Voilà la version une du prgm de cryptage/décryptage !

Code:

'menu
[début]
print "Voulez-vous crypter ou décrypter?"
print "1) crypter"
print "2) décrypter"
input nb
if nb < 1 or nb > 2 then goto [début]
if nb = 1 then goto [crypter]

'code pour décrypter (inverse du cryptage)
[décrypter]
print
print "décryptage :"
input "Clé : " ; clé$
input "Texte : " ; ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) - cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

for z = 1 to ch
    if lcr(z) < 33 then lcr(z) = lcr(z) + 92
    if chr$(lcr(z)) = "þ" then
        txtcr$ = txtcr$ + " "
    else
        txtcr$ = txtcr$ + chr$(lcr(z))
    end if
next

print txtcr$
goto [cx]

'code pour crypter
[crypter]

print
print "cryptage"
input "Clé : " ; clé$
input "Texte : " ; ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
for z = 1 to ch
    'crypte avec les caractères couramment utilisé au clavier
    if lcr(z) > 126 then lcr(z) = lcr(z) - 92
    txtcr$ = txtcr$ + chr$(lcr(z))
next

'affiche la réponse
print txtcr$
goto [cx]

[cx]
print
print "Voulez-vous recommencez"
print "1) Oui"
print "2) non"
input nb
print
if nb = 1 then goto [début]
end

P.S. : Je ne sais pas pourquoi, mais on ne peut pas faire de copier coller!

Voilà, je vais maintenant créer une interface d'utilisateur big smile [/code]
Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Mike
Admin
Admin
Mike


Nombre de messages : 724
Age : 32
Localisation : Canada, Québec Montréal
language de prog : LB, GM, C++, XHTML, CSS, PHP
expérience en prog : 1 ans d'expérience
Date d'inscription : 21/07/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptySam 20 Aoû - 16:04

Ça a l'air super. Si tu as des questions n'hésite pas
Revenir en haut Aller en bas
https://info-programmation.forumactif.com/
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyMar 23 Aoû - 5:43

Voici le même programme avec une interface utilisateur. je programe

Il y a encore quelques modifications à faire pour le terminer.

Code:

WindowHeight = 180
WindowWidth = 230
UpperLeftX = 100
UpperLeftY = 50
menu #1, "&Fichier", "Nouveau", [new], "Ouvrir", [ouvrir], "Enregistrer", [enr], "Quitter", [quit]
radiobutton #1.rc, "Crypter", [crypter], [wait], 10, 10, 50, 20
radiobutton #1.rd, "Décrypter", [décrypter], [wait], 70, 10, 70, 20
statictext #1, "Clé :", 10, 40, 50, 20
statictext #1, "Texte :", 10, 70, 50, 20
textbox #1.clé, 60, 40, 150, 20
textbox #1.txt, 60,70, 150, 20
button #1.cr, "Crypter", [cr], UL, 10, 100, 100, 20
button #1.dy, "Décrypter", [dy], UL, 110, 100, 100, 20
open "crypter v: 2.0" for Window as #1
#1.cr, "!hide"
#1.dy, "!hide"
print "trapclose [quit]"
wait

[crypter]
#1.dy, "!hide"
#1.cr, "!show"
wait

[décrypter]
#1.cr, "!hide"
#1.dy, "!show"
wait

'code pour décrypter (inverse du cryptage)
[dy]
print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) - cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtdé$ = ""

for z = 1 to ch
    if lcr(z) < 33 then lcr(z) = lcr(z) + 92
    if chr$(lcr(z)) = "|" then
        txtdé$ = txtdé$ + " "
    else
        txtdé$ = txtdé$ + chr$(lcr(z))
    end if
next

txtcr$ = ""
print txtdé$
wait

'code pour crypter
[cr]

print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
for z = 1 to ch
    'crypte avec les caractères couramment utilisé au clavier
    if lcr(z) > 126 then lcr(z) = lcr(z) - 92
    txtcr$ = txtcr$ + chr$(lcr(z))
next

'affiche la réponse
txtdé$ = ""
print txtcr$
wait

[quit]
close #1
end

[wait]
wait

[enr]
nom$ = ""
filedialog "Enregistrer :", "*.txt", nom$
if nom$ = "" then goto [close]
if txtcr$ = "" then goto [close]
nom$ = nom$ + ".txt"
open nom$ for output as #enregistrer
print #enregistrer, txtcr$
print #1.txt, ""
print #1.clé, ""
close #enregistrer
[close]
wait

[ouvrir]
nom$ = ""
filedialog "Ouvrir :", "*.txt", nom$
if nom$ = "" then goto [closeo]
open nom$ for input as #ouvrir
line input #ouvrir, drc$
print #1.txt, drc$
print #1.clé, ""
close #ouvrir
[closeo]
wait

[new]
print #1.clé, ""
print #1.txt, ""
txtcr$ = ""
txtdy$ = ""
wait
Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyMar 23 Aoû - 10:25

Voilà, ça doit être bon. zzz
Je le poste aussi dans la rubrique programme
Code:
'***************************************************
'* CRYPTAGE v:2.1                                  *
'*                                                *
'* Created by Black Templar Août 2005              *
'*                                                *
'* programme permettant de crypter, décrypter et  *
'* enregistrer des données en format ".txt"        *
'*                                                *
'* OPEN SOURCE                                    *
'***************************************************
nomainwin
dim tx$(5)
WindowHeight = 275
WindowWidth = 230
UpperLeftX = 100
UpperLeftY = 50
menu #1, "&Fichier", "Nouveau", [new], "Ouvrir", [ouvrir], "Enregistrer", [enr], "Quitter", [quit]
radiobutton #1.rc, "Crypter", [crypter], [wait], 10, 10, 50, 20
radiobutton #1.rd, "Décrypter", [décrypter], [wait], 70, 10, 70, 20
statictext #1, "Clé :", 10, 40, 50, 20
statictext #1, "Texte :", 10, 70, 50, 20
statictext #1, "Résultat :", 10, 130, 50, 20
textbox #1.clé, 60, 40, 150, 20
textbox #1.txt, 60,70, 150, 20
button #1.cr, "Crypter", [cr], UL, 10, 100, 100, 20
button #1.dy, "Décrypter", [dy], UL, 110, 100, 100, 20
texteditor #1.txedit, 60, 130, 150, 80
open "crypter v: 2.1" for Window as #1
print #1, "trapclose [quit]"
#1.cr, "!hide"
#1.dy, "!hide"
call NoEdit
wait

[crypter]
#1.dy, "!hide"
#1.cr, "!show"
wait

[décrypter]
#1.cr, "!hide"
#1.dy, "!show"
wait

'code pour décrypter (inverse du cryptage)
[dy]
print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) - cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtdé$ = ""

for z = 1 to ch
    if lcr(z) < 33 then lcr(z) = lcr(z) + 92
    if chr$(lcr(z)) = "|" then
        txtdé$ = txtdé$ + " "
    else
        txtdé$ = txtdé$ + chr$(lcr(z))
    end if
next

txtcr$ = ""
print txtdé$
tx$(1) = txtdé$
goto [result]
wait

'code pour crypter
[cr]

print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
for z = 1 to ch
    'crypte avec les caractères couramment utilisé au clavier
    if lcr(z) > 126 then lcr(z) = lcr(z) - 92
    txtcr$ = txtcr$ + chr$(lcr(z))
next

'affiche la réponse
txtdé$ = ""
print txtcr$
tx$(1) = txtcr$
goto [result]
wait

[quit]
close #1
end

[wait]
wait

'********** Enregistrement **********
[enr]
nom$ = ""
filedialog "Save as...", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
wait
end if
if txtcr$ = "" then
notice "Il n'y a rien à enregistrer !"
wait
end if
nom$ = nom$ + ".txt"
open nom$ for output as #enregistrer
print #enregistrer, txtcr$
print #1.txt, ""
print #1.clé, ""
print #1.txedit, "!cls"
close #enregistrer
wait

'********** Ouvrir un fichier **********
[ouvrir]
nom$ = ""
filedialog "Ouvrir :", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
goto [ouvrir]
end if
if right$(nom$, 4) <> ".txt" then
notice "Vous devez selectionner un fichier texte !"
wait
end if
open nom$ for input as #ouvrir
line input #ouvrir, drc$
print #1.txt, drc$
print #1.clé, ""
print #1.txedit, "!cls"
close #ouvrir
wait

[new]
print #1.clé, ""
print #1.txt, ""
print #1.txedit, "!cls"
txtcr$ = ""
txtdy$ = ""
wait

'********** Affiche le résultat dans Texteditor **********
[result]
if len(tx$(1)) > 105 then
notice "Vous ne pouvez pas dépacer 105 caractère !"
wait
end if
print #1.txedit, "!cls"
a = 1
while len(tx$(1)) > 21
a = a + 1
tx$(a) = left$(tx$(1), 21)
tx$(1) = right$(tx$(1), len(tx$(1)) - 21)
wend
for z = 2 to a
print #1.txedit, tx$(z)
next
print #1.txedit, tx$(1)
wait


'********** Efface le menu "edit" **********
Sub NoEdit
    hMain=hWnd(#1)
    hMainMenu=GetMenu(hMain)
    hMainEdit=GetSubMenu(hMainMenu,1)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#1)
    End Sub

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As long, r As boolean
    End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As long, nPos As long,_
    GetSubMenu As long
    End Function

Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As long,_
    GetMenu As long
    End Function

Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As long,_
    hSubMenu As long, _MF_BYCOMMAND As long,_
    RemoveMenu As boolean
    End Function

Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Mike
Admin
Admin
Mike


Nombre de messages : 724
Age : 32
Localisation : Canada, Québec Montréal
language de prog : LB, GM, C++, XHTML, CSS, PHP
expérience en prog : 1 ans d'expérience
Date d'inscription : 21/07/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyMar 23 Aoû - 10:33

Oui, il commence a être bon. Mais faudrait que tu rajoute l'option copié/collé
Et agrandir la partie texte et la fenêtre
Revenir en haut Aller en bas
https://info-programmation.forumactif.com/
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyMar 23 Aoû - 10:35

ok.
Je sais pas faire le copier coller, mais je vais me débrouiller.
Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Exedor
programmeur intensif
programmeur intensif
Exedor


Nombre de messages : 304
language de prog : Commence juste d'apprendre le C++
expérience en prog : Passé pas Liberty Basic et blitz basic sans m'arréter.
Date d'inscription : 19/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyVen 26 Aoû - 12:37

J'ai essayé, c'est super ! pouce levé applaudisemment
Revenir en haut Aller en bas
http://fanasdharrypotter.free.fr
Black Templar
Admin
Admin
Black Templar


Nombre de messages : 356
Age : 35
Localisation : Lille (France)
language de prog : Liberty BASIC; HTML; CSS; php; MySQL; C
expérience en prog : Amateur
Date d'inscription : 06/08/2005

cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage EmptyVen 26 Aoû - 17:25

Voici les dernière modif. Le Bub de l'extention .txt.txt est résolu
Code:
'***************************************************
'* CRYPTAGE v:2.2                                  *
'*                                                *
'* Created by Black Templar Août 2005              *
'*                                                *
'* programme permettant de crypter, décrypter et  *
'* enregistrer des données en format ".txt"        *
'*                                                *
'* OPEN SOURCE                                    *
'***************************************************
nomainwin
dim tx$(5)
WindowHeight = 275
WindowWidth = 230
UpperLeftX = 100
UpperLeftY = 50
menu #1, "&Fichier", "Nouveau", [new], "Ouvrir", [ouvrir], "Enregistrer", [enr], "Quitter", [quit]
radiobutton #1.rc, "Crypter", [crypter], [wait], 10, 10, 50, 20
radiobutton #1.rd, "Décrypter", [décrypter], [wait], 70, 10, 70, 20
statictext #1, "Clé :", 10, 40, 50, 20
statictext #1, "Texte :", 10, 70, 50, 20
statictext #1, "Résultat :", 10, 130, 50, 20
textbox #1.clé, 60, 40, 150, 20
textbox #1.txt, 60,70, 150, 20
button #1.cr, "Crypter", [cr], UL, 10, 100, 100, 20
button #1.dy, "Décrypter", [dy], UL, 110, 100, 100, 20
texteditor #1.txedit, 60, 130, 150, 80
open "crypter v: 2.1" for Window as #1
print #1, "trapclose [quit]"
#1.cr, "!hide"
#1.dy, "!hide"
call NoEdit
wait

[crypter]
#1.dy, "!hide"
#1.cr, "!show"
wait

[décrypter]
#1.cr, "!hide"
#1.dy, "!show"
wait

'code pour décrypter (inverse du cryptage)
[dy]
print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) - cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtdé$ = ""

for z = 1 to ch
    if lcr(z) < 33 then lcr(z) = lcr(z) + 92
    if chr$(lcr(z)) = "|" then
        txtdé$ = txtdé$ + " "
    else
        txtdé$ = txtdé$ + chr$(lcr(z))
    end if
next

txtcr$ = ""
print txtdé$
tx$(1) = txtdé$
goto [result]
wait

'code pour crypter
[cr]

print #1.clé, "!contents?"
input #1.clé, clé$
print #1.txt, "!contents?"
input #1.txt, ch$
ch$ = trim$(ch$)
ch = len(ch$)
dim lcr(ch)

'crypte le txt (utilise l'ASCII)
for z = 1 to ch
    cr$ = mid$(ch$,z,1)
    lcr(z) = asc(cr$)
next

'par le m^ procédé, crypte la clé
for z = 1 to len(clé$)
    cr$ = mid$(clé$,z,1)
    cléc(z) = asc(cr$)
next

'Additionne le cryptage clé avec celui du txt
cl = 1
for z = 1 to ch
    lcr(z) = lcr(z) + cléc(cl)
    cl = cl + 1
    if cl > len(clé$) then cl = 1
next

txtcr$ = ""

'Transforme le cryptage numérique en alphanumérique grâce à l'ASCII
for z = 1 to ch
    'crypte avec les caractères couramment utilisé au clavier
    if lcr(z) > 126 then lcr(z) = lcr(z) - 92
    txtcr$ = txtcr$ + chr$(lcr(z))
next

'affiche la réponse
txtdé$ = ""
print txtcr$
tx$(1) = txtcr$
goto [result]
wait

[quit]
close #1
end

[wait]
wait

'********** Enregistrement **********
[enr]
nom$ = ""
filedialog "Save as...", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
wait
end if
if txtcr$ = "" then
notice "Il n'y a rien à enregistrer !"
wait
end if
if right$(nom$, 4) <> ".txt" then
    nom$ = nom$ + ".txt"
end if
open nom$ for output as #enregistrer
print #enregistrer, txtcr$
print #1.txt, ""
print #1.clé, ""
print #1.txedit, "!cls"
close #enregistrer
wait

'********** Ouvrir un fichier **********
[ouvrir]
nom$ = ""
filedialog "Ouvrir :", "*.txt", nom$
if nom$ = "" then
notice "tapez un nom de fichier !"
wait
end if
if right$(nom$, 4) <> ".txt" then
notice "Vous devez selectionner un fichier texte !"
wait
end if
open nom$ for input as #ouvrir
line input #ouvrir, drc$
print #1.txt, drc$
print #1.clé, ""
print #1.txedit, "!cls"
close #ouvrir
wait

[new]
print #1.clé, ""
print #1.txt, ""
print #1.txedit, "!cls"
txtcr$ = ""
txtdy$ = ""
wait

'********** Affiche le résultat dans Texteditor **********
[result]
if len(tx$(1)) > 105 then
notice "Vous ne pouvez pas dépacer 105 caractère !"
wait
end if
print #1.txedit, "!cls"
a = 1
while len(tx$(1)) > 21
a = a + 1
tx$(a) = left$(tx$(1), 21)
tx$(1) = right$(tx$(1), len(tx$(1)) - 21)
wend
for z = 2 to a
print #1.txedit, tx$(z)
next
print #1.txedit, tx$(1)
wait


'********** Efface le menu "edit" **********
Sub NoEdit
    hMain=hWnd(#1)
    hMainMenu=GetMenu(hMain)
    hMainEdit=GetSubMenu(hMainMenu,1)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#1)
    End Sub

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As long, r As boolean
    End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As long, nPos As long,_
    GetSubMenu As long
    End Function

Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As long,_
    GetMenu As long
    End Function

Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As long,_
    hSubMenu As long, _MF_BYCOMMAND As long,_
    RemoveMenu As boolean
    End Function


Revenir en haut Aller en bas
http://membres.multimania.fr/templar59
Contenu sponsorisé





cryptage et décryptage Empty
MessageSujet: Re: cryptage et décryptage   cryptage et décryptage Empty

Revenir en haut Aller en bas
 
cryptage et décryptage
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» cryptage de données
» cryptage d'une carte bancaire

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
Tout sur la programmation :: Programmation :: Vos projet-
Sauter vers: