0% found this document useful (0 votes)
29 views

1.1 Afisare Recursiv: Stdio.h Stdlib.h

The document contains code for recursively printing numbers with decreasing steps and code for encrypting and decrypting messages. The recursive function takes in a number and step size and prints the number, decreases it by the step size, calls itself recursively, and then prints the number again. The encryption/decryption code defines functions to encrypt and decrypt messages by shifting each character by the corresponding character in a key. It takes in a message and key as strings, finds the lengths, generates a repeated key if it is shorter than the message, encrypts the message, and prints the encrypted output.

Uploaded by

Bogdan Airinei
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)
29 views

1.1 Afisare Recursiv: Stdio.h Stdlib.h

The document contains code for recursively printing numbers with decreasing steps and code for encrypting and decrypting messages. The recursive function takes in a number and step size and prints the number, decreases it by the step size, calls itself recursively, and then prints the number again. The encryption/decryption code defines functions to encrypt and decrypt messages by shifting each character by the corresponding character in a key. It takes in a message and key as strings, finds the lengths, generates a repeated key if it is shorter than the message, encrypts the message, and prints the encrypted output.

Uploaded by

Bogdan Airinei
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/ 3

1.

1 Afisare recursiv

#include <stdio.h>
#include <stdlib.h>

void recursion(int n, int pas)


{
if(n>=0)
{
printf(" %d ",n);
n-=pas;
recursion(n,pas);
printf(" %d ",n);
}
}
int main(void) {
int n=11;
int pas=2;
recursion(n, pas);
return 0;
}

1.2.

#include <stdio.h>
#include <stdlib.h>

char* en;
char* dn;
char *message;
char *key;

int mystrlen(char *p)


{
int len=0;
while(*p!='\0')
{
len++;
*p++;
}
return len;
}
void encrypt(char message[], char key[], int dim)
{
for(int i=0;i<dim;i++)
{
en[i]=(message[i]+key[i])%26;
}
}

void decrypt(char message[], char key[], int dim)


{
for(int i=0;i<dim;i++)
{
dn[i]=(en[i]-message[i]+26)%26;
}
}
int main(void) {
message=(char*)malloc(sizeof(char));
key=(char*)malloc(sizeof(char));
//en=(char*)malloc(sizeof(char));
//dn=(char*)malloc(sizeof(char));
char en[100];
char dn[100];
char *k;
int dim=10;
printf("\nmessage=");
scanf("%s", message);
printf("\nkey=");
scanf("%s", key);
int nk=mystrlen(key);
int nm=mystrlen(message);
printf("\n nk=%d", nk);

int q=0, l=0;


while(q!=nm) //cat timp dim key e mai mica decat dim mesaj
{
if(l<nk)
{
k[q++]=key[l++];
}
else
{
l=0;
}
}
printf("\ngenerated key= %s", k);

encrypt(message, k, nm);
//decrypt(message, k, nm);

printf("\n encrypt=%s", en);


//printf("\n decrypt=%s", dn);

return 0;
}

You might also like