0% found this document useful (0 votes)
73 views7 pages

Popușoi Alexandru Grupa: B-1841: Lucrare de Laborator NR 2 Tema: Operații Criptografice, Protocoale Criptografice

This document describes a cryptography lab assignment that implements simple encryption and decryption algorithms as well as mathematical encryption and decryption algorithms using a Caesar cipher. The code includes three source code files that define the encryption and decryption functions, declare variables, and contain a main function to run the algorithms. Screenshots show examples of encrypting and decrypting messages to verify the algorithms are working correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views7 pages

Popușoi Alexandru Grupa: B-1841: Lucrare de Laborator NR 2 Tema: Operații Criptografice, Protocoale Criptografice

This document describes a cryptography lab assignment that implements simple encryption and decryption algorithms as well as mathematical encryption and decryption algorithms using a Caesar cipher. The code includes three source code files that define the encryption and decryption functions, declare variables, and contain a main function to run the algorithms. Screenshots show examples of encrypting and decrypting messages to verify the algorithms are working correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lucrare de laborator nr 2

Tema: Operații criptografice, Protocoale Criptografice


Popușoi Alexandru
Grupa: B-1841

Codul sursa:

Fișierul lab1.c
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include "csr.c"

int main(int argc, char *argv[])

char *prg=argv[0];

char *opt=argv[1];

char *msg=argv[2];

if(argc == 1) {

fprintf(stderr, "%s: no option and message\n", prg);

exit(3);

if(argc == 2) {

if(opt[0] == '-') {

fprintf(stderr, "no message\n");

else if(opt[0] != '-'){

fprintf(stderr, "%s: no option\n");


}

exit(2);

//int m;

if(argc == 3) {

if(strcmp(opt,"-Ecsr") == 0)

printf("Simple encryption\n");

CSR_encrypt(msg);

else if(strcmp(opt,"-Ecsrm") == 0)

printf("Math Encryption\n");

CSR_enc_math(msg);

else if(strcmp(opt,"-Dcsr") == 0)

printf("Simple Decription\n");

CSR_decrypt(msg);

else if(strcmp(opt,"-Dcsrm") == 0)

printf("Math Decryption\n");

CSR_decrypt_math(msg);

else {

fprintf(stderr, "%s: illegal option: %s\n", prg, opt);

exit(1);

if(argc > 3) {
fprintf(stderr, "too many strings!!!");

exit(0);

Fișierul csr.c
#include "vars.c"

void CSR_encrypt(char msg[])

printf("key: ");

scanf("%i", &key);

for(i=0; i < strlen(msg); i++)

for(j=0; j < strlen(letters); j++)

if(msg[i] == letters[j])

if((j + key) < strlen(letters))

enc[i] = letters[ j + key ];

else

k = ( j + key ) - strlen(letters);

enc[i] = letters[k];

printf("enc: ");

for(i = 0; i < strlen(msg); i++)

printf("%c", enc[i]);

printf("\n");

}
void CSR_enc_math(char msg[])

printf("key: ");

scanf("%i", &key);

for(i = 0; i < strlen(msg); i++)

for(j = 0; j < strlen(letters); j++)

if(msg[i] == letters[j])

k = ( j + key ) % strlen(letters);

enc[i] = letters[k];

if(( j + key ) < strlen(letters))

enc[i] = letters[ j + key];

else

k = ( j + key ) - strlen(letters);

enc[i] = letters[k];

printf("enc: ");

for(i = 0; i < strlen(msg); i++)

printf("%c", enc[i]);

printf("\n");

void CSR_decrypt(char msg[])

printf("key: ");

scanf("%i", &key);

for(i = 0; i < strlen(msg); i++)


for(j = 0; j < strlen(letters); j++)

if(msg[i] == letters[j])

k = ( j - key ) % strlen(letters);

dec[i] = letters[k];

if(( j - key ) < strlen(letters))

dec[i] = letters[ j - key];

else

k = ( j - key )+ strlen(letters);

dec[i] = letters[k];

printf("dec: ");

for(i = 0; i < strlen(msg); i++)

printf("%c", dec[i]);

printf("\n");

void CSR_decrypt_math(char msg[])

printf("key: ");

scanf("%i", &key);

for(i = 0; i < strlen(msg); i++)

for(j = 0; j < strlen(letters); j++)

if(msg[i] == letters[j])

k = ( j - key ) % strlen(letters);
dec[i] = letters[k];

if(( j - key ) < strlen(letters))

dec[i] = letters[ j - key ];

else

k = ( j - key ) + strlen(letters);

dec[i] = letters[k];

printf("dectyption: ");

for(i=0; i<strlen(msg); i++)

printf("%c", dec[i]);

printf("\n");

Fișierul vars.c
char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char enc[25];

char dec[25];

int key, i, j, k;

Screenshoturi
 Verificăm corectitudinea criptării:
 Verificăm corectitudinea decriptării:

 Verificăm corectitudinea criptării matematice dupa modelul de mai sus:

 Verificăm corectitudinea decriptării modelului matematic la fel după


modelul de mai sus:

You might also like