|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Nov 2002
Messaggi: 173
|
[C] Cryptare e decriptare
questo codice è stato modificato da P8257 WebMaster
risolve il problema del gets , ma adesso non funziona piu la funzione Decrypt (cioè da valori sballati) Codice:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <conio.h>
/*
Name: CRYDEC TOKI
Author: KRAKZ
Date: 25/02/03 23.08
Description: CRYPTA E DECRYPTA
LICENZA : GNU|GPL
VERSIONE : 1.0
RINGRAZIAMENTI : P8257 WebMaster ,
*/
void crypt (void) ;
void decrypt (void) ;
# define MAX 255
int main (void)
{
printf (" *** BENVENUTO SU CRYDEC VERSIONE 1.0 ***\n\n\n") ;
printf ("SELEZIONA UNA DELLE OPZIONI\n\n") ;
printf ("1 - Crypta\n") ;
printf ("2 - Decrypta\n") ;
printf ("3 - Info autori\n") ;
printf ("Digita 1, 2 o 3 ");
while (1)
{
switch(getch()) {
case 0+'1': crypt () ;
break ;
case 0+'2': decrypt () ;
break ;
case 0+'3': printf ("Krakz") ;
break ;
default: exit(0);
}
}
return 0;
}
void crypt (void)
{
int i, I = 0 , countchiave , countfrase , crypt[MAX] ;
char frase[MAX]="\0" , chiave[MAX]="\0" , nomefile[10]="\0" ;
FILE *cfPtr , *apri ;
printf ("Benvenuto su crypt 0.5\n") ;
printf ("Inserisci frase\n") ;
gets(frase) ;
printf ("Inserisci chiave\n") ;
gets(chiave) ;
printf ("Salva con nome\n") ;
gets(nomefile) ;
countfrase = strlen(frase) ; /* VERIFICA LA LUNGHEZZA DELLE STRINGHE */
countchiave = strlen(chiave) ;
for ( i = 0 ; countfrase > i ; i++) /* CONTROLLA CHE TUTTA LA STRINGA SIA CRIPTATA */
{
if ( countchiave < I) I = 0 ;; /* CONTROLLA SE SONO STATE UTILIZZATE TUTTE LE LETTERE DELLA CHIAVE
SE VEDE CHE SONO STATE USATE TUTTE , RESETTA IL TUTTO PARTENDO
DALLA PRIMA LETTERA */
crypt[i] = chiave[I] + frase[i] ; /* CRIPTA LA STRINGA */
if ((cfPtr = fopen( nomefile , "a")) == NULL)
printf("File gia aperto\n");
if ( crypt[i] < 100 ) fprintf(cfPtr, "0" ) ;; /* VERIFICA CHE IL VALORE DATO SIA MAGGIORE DI 100
E SE RISCONTRA UN VALORE MINORE DI 100 AGGIUNGE
IL VALORE 0 */
fprintf(cfPtr, "%d", crypt[i] ); /* STAMPA LA FRASE CRIPTATA */
I = 1 + I ; /* REALIZZA UNO SHIFT A DESTRA */
}
fprintf(cfPtr, "\n\n\nUsa decrypt per vedere il testo\n\n" ) ;
fprintf(cfPtr, "\n\n\nVersione programma 1.0\n\n" ) ;
fprintf(cfPtr, "\n\n\nwww.toki.it\n\n" ) ;
printf ("Il file testo è stato cryptato , per decryptarlo") ;
getch();
}
void decrypt (void)
{
int I=0 , i , countfrase , countchiave , dEcrypt[MAX] , de = 0 ;
char frase[MAX]="\0" , chiave[MAX]="\0" ;
printf ("Inserisci File Cryptato\n") ;
gets(frase) ;
printf ("Inserisci chiave\n") ;
gets(chiave) ;
countfrase = strlen(frase) ;
countchiave = strlen(chiave) ;
for ( i = 0 ; countfrase > i ; i = 3 + i)
{
if ( countchiave < I)
I = 0 ;;
dEcrypt[de] = (frase[i]* 100 + frase [i+1] * 10 + frase [i+2] +48 ) - chiave [I] ;
printf ("%c" , dEcrypt[I]) ;
I = 1 + I ;
}
getch();
}
__________________
powered by Mandrake - You are registered as user #335131 with the Linux Counter |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2002
Messaggi: 173
|
problema risolto
potete chiudere il 3d
__________________
powered by Mandrake - You are registered as user #335131 with the Linux Counter |
|
|
|
|
|
#3 |
|
Bannato
Iscritto dal: Feb 2003
Città: genova
Messaggi: 130
|
ricordati che un cifrario in one time pad per essere inviolabile deve avere la chiave della stessa lunghezza del testo in chiaro.
nel momento in cui riazzeri il conto e riparti dall'inizio della chiave crei un buco nella sicurezza del codice. ciauz |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Nov 2002
Messaggi: 173
|
ho capito gia ho trovato un paio di bugs
__________________
powered by Mandrake - You are registered as user #335131 with the Linux Counter |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:34.


















