Red de conocimiento informático - Aprendizaje de programación - Programación Helloworld

Programación Helloworld

Este es un artículo que escribí en mi blog antes.

El principio del cifrado Vigenere:

Supongamos que hay una clave Vigenere (2, 4, 8, 12, 7) que quiere cifrar el texto sin formato helloworld.

Mueve la primera letra del texto plano helloworld en 2 bits, la segunda letra en 4 bits,..., la quinta letra en 7 bits y luego realiza un bucle desde el encabezado de la clave hasta todo el texto plano de hello world. se convierten en texto cifrado.

# include & ltiostream & gt

# include & ltctime & gt

#Definir clave EN 10 //Longitud de clave

Uso espacio de nombres estándar

cifrado vacío(char * simple, cifrado char*, clave int[]);

cifrado vacío(cifrado char*, clave int[]);

int main()

{

char * cipher = nuevo char[27];

srand((unsigned)time( 0));

int key[key len];//key

for(int I = 0;I<KEYLENi++)key[I]= rand()% 15+ 5;

encrypt("hello rold!iamleukotrichia", contraseña, clave); //Generar texto cifrado y almacenarlo con contraseña.

cout & lt& lt"Ciphertext:"

Contraseña (Cifrado, clave

Sistema ("pausa"); Devuelve 0;

}

void encrypt(char * Plain, char * cipher, int key[]) // Genera texto cifrado.

{

int I = 0;

mientras(*plain)

{

si (i & gt= clave len)I = 0;

* cifrado =(* simple++)+clave[I];

cifrado++;

i++;

i++;

i++ p>

}

* cifrado = ' \ 0

Retorno

}

Voidcipher (char * cipher, int key[])//Decrypt

{

int I = 0;

cout & lt& lt"Texto sin formato:";

while(*contraseña)

{

Si (i & gt= clave len)I = 0;

cout & lt& lt(char)(* cipher++)-clave[I]);

i++;

}

cout & lt& ltendl

Regreso;

}