Initial commit
This commit is contained in:
parent
201c2be476
commit
d44d462dfa
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.log
|
||||
a.out
|
||||
tmp/
|
24
cherry.c
Normal file
24
cherry.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "cherry.h"
|
||||
#include <string.h>
|
||||
|
||||
void cherry_encrypt(char cherry[], char crystal[], int mask[]) {
|
||||
int i;
|
||||
for (i = 0; i < strlen(cherry) - 1; i++) {
|
||||
mask[i] = cherry[i] - crystal[i];
|
||||
}
|
||||
for (i = strlen(cherry) - 1; i < strlen(crystal) - 1; i++) {
|
||||
mask[i] = crystal[i];
|
||||
}
|
||||
}
|
||||
|
||||
void cherry_decrypt(char cherry[], char crystal[], int mask[], int length) {
|
||||
int i, end = 1;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (i == strlen(cherry) - 1 || end == 0) {
|
||||
crystal[i] = mask[i];
|
||||
end = 0;
|
||||
} else {
|
||||
crystal[i] = cherry[i] - mask[i];
|
||||
}
|
||||
}
|
||||
}
|
7
cherry.h
Normal file
7
cherry.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef CHERRY_H_
|
||||
#define CHERRY_H_
|
||||
|
||||
void cherry_encrypt(char cherry[], char crystal[], int mask[]);
|
||||
void cherry_decrypt(char cherry[], char crystal[], int mask[], int);
|
||||
|
||||
#endif // CHERRY_H_
|
35
example.c
Normal file
35
example.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cherry.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
const int size = 1028;
|
||||
char cherry[size], cherry2[size], crystal[size], crystal2[size];
|
||||
int mask[size], mask2[size], i;
|
||||
int length = 0;
|
||||
puts("Enter the Cherry: ");
|
||||
fgets(cherry, size, stdin);
|
||||
puts("Enter the Crystal: ");
|
||||
fgets(crystal, size, stdin);
|
||||
cherry_encrypt(cherry, crystal, mask);
|
||||
for (i = 0; i < strlen(crystal) - 1; i++) {
|
||||
printf("%d ", mask[i]);
|
||||
length++;
|
||||
}
|
||||
printf("\nYour mask is : %d characters long", length);
|
||||
puts("\n===Decryption: ===\n");
|
||||
puts("Enter the Cherry: ");
|
||||
fgets(cherry2, size, stdin);
|
||||
puts("Enter the size of the Mask: ");
|
||||
scanf("%d", &length);
|
||||
puts("Enter the mask: ");
|
||||
for (i = 0; i < length; i++) {
|
||||
scanf("%d", &mask2[i]);
|
||||
}
|
||||
puts("The Crystal is: ");
|
||||
cherry_decrypt(cherry2, crystal2, mask2, length);
|
||||
puts(crystal2);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user