Professional Documents
Culture Documents
Agenda cu teorie- o pagina fata—verso pentru fiecare curs; maxim 3 linii de cod pe pagina;
Matrix encryption and
decryption
1. Encryption program:
Function main
{
print "Enter a sequence to be encrypted"
get sequence from keyboard: ‘seq’
print "Enter a generating code"
get sequence from keyboard: ‘cod’
n = length of ‘seq’
l = length of ‘cod’
initialize function interschimbare(cod,l)
print "Encrypted message: "
initialize function criptare(seq,n)
//new line//
print "Encryption code: "
print ‘cod’
}
2. Decryption program:
Function main
{
do{
//new line//
print "Please introduce the password to proceed decrypting the message: "
while (‘1’ // infinite loop)
ch = read char from keyboard without echo
if ch == ENTER
password[i] ='\0';
break;
else if ch == BKSPC
if i>0
decrement I by 1
printf("\b \b");
else if ch == TAB || ch == SPACE
continue;
else
password[i] = ch;
increment I by 1
printf("*");
if strcmp(password,set) == 0
print " Access granted"
break;
else
print " Access denied"
increment ct by 1
{
declaring mat[6][5] = {
{65,66,67,68,69},
{70,71,72,73,74},
{75,76,77,78,79},
{80,81,82,83,84},
{85,86,87,88,89},
{90}
};
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "functii.cpp"
int main()
{
int meniu,n,i,cod1,cod2,j,m,conv,l,z;
char pahar,v[300],seq[100],c,cod[10];
n = strlen(seq);
l = strlen(cod);
interschimbare(cod,l);
criptare(seq,n);
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "functii.cpp"
#define ENTER 13
#define BKSPC 8
#define TAB 9
#define SPACE 32
int main()
{
char ch,password[10],set[10] = "ROOT",pahar,seq[100],cod[10];
int ct = 0,cod1,cod2,n,i,j,l,z;
do
{
int i=0;
printf("\nPlease introduce the password to proceed decrypting the message: ");
while(1)
{
ch = getch();
if(ch == ENTER)
{
password[i] ='\0';
break;
}
else if(ch == BKSPC)
{
if(i>0)
{
i--;
printf("\b \b");
}
}
else if(ch == TAB || ch == SPACE)
{
continue;
}
else
{
password[i] = ch;
i++;
printf("*");
}
}
if(strcmp(password,set) == 0)
{
puts(" Access granted");
break;
}
else
{
puts(" Access denied");
} //verificare la tastare parola
ct++;
} while(ct != 3);
if(ct == 3)
{
exit(1);
}
fflush(stdin);
puts("Enter a sequence to be decrypted: ");
gets(seq);
n = strlen(seq);
l = strlen(cod);
interschimbare(cod,l);
decriptare(seq,n);
3. The functions:
A. The first function:
printf("%c",mat[m-48][k-48]);
}