Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void initMatrix(char *matrix)
- {
- int index = 0;
- for (int i = 48; i <= 57; i++) {
- matrix[index] = i;
- index++;
- }
- for (int i = 65; i <= 90; i++) {
- matrix[index] = i;
- index++;
- }
- for (int i = 97; i <= 122; i++) {
- matrix[index] = i;
- index++;
- }
- matrix[62] = ' ';
- matrix[63] = ',';
- }
- void mapMatrix(char *input, char *matrix, char *cypher) {
- int index = 0;
- char * ptr;
- ptr = strtok (input," ");
- while (ptr != NULL) {
- int n = atoi(ptr);
- cypher[index] = matrix[n];
- ptr = strtok (NULL, " ");
- index++;
- }
- }
- void decrypt(char *hash, char *input, char *cypher) {
- }
- void encrypt(char *hash, char *input, char *cypher) {
- int offset = 0;
- for (int i = 0; i < 256; i++) {
- if (input[i] == '\0')
- return;
- for (int j = 0; j < 64; j++)
- if (hash[i % (strlen(hash) - 1)] == cypher[j]) {
- offset = j;
- break;
- }
- for (int j = 0; j < 64; j++)
- if (input[i] == cypher[j]) {
- printf("%c", cypher[(j + offset) % (strlen(cypher) - 1)]);
- }
- }
- }
- int main() {
- char matrix[64];
- char cypher[64];
- char input[256];
- char hash[256];
- char operation[9];
- initMatrix(matrix);
- fgets(operation, sizeof(operation), stdin);
- fgets(input, sizeof(input), stdin);
- mapMatrix(input, matrix, cypher);
- fgets(hash, sizeof(hash), stdin);
- fgets(input, sizeof(input), stdin);
- if (!(strcmp(operation, "encrypt\n")))
- encrypt(hash, input, cypher);
- else if (!(strcmp(operation, "decrypt\n")))
- decrypt(hash, input, cypher);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement