Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 256 // 2^8
- void swap(unsigned char *a, unsigned char *b) //Карра Кееро Карра Кееро
- {
- int tmp = *a;
- *a = *b;
- *b = tmp;
- }
- int KSA(char *key, unsigned char *S) //Да, да, курсач тоже будешь в ночь делать?
- {
- int len = strlen(key);
- int j = 0;
- for(int i = 0; i < N; i++)
- S[i] = i;
- for(int i = 0; i < N; i++)
- {
- j = (j + S[i] + key[i % len]) % N;
- swap(&S[i], &S[j]);
- }
- return 0;
- }
- int PRGA(unsigned char *S, char *plaintext, unsigned char *ciphertext) //Ну хули ты начинаешь, нормально же общались
- {
- int i = 0;
- int j = 0;
- for(size_t n = 0, len = strlen(plaintext); n < len; n++)
- {
- i = (i + 1) % N;
- j = (j + S[i]) % N;
- swap(&S[i], &S[j]);
- int rnd = S[(S[i] + S[j]) % N];
- ciphertext[n] = rnd ^ plaintext[n];
- }
- return 0;
- }
- int RC4(char *key, char *plaintext, unsigned char *ciphertext) //Вот скажи мне, Олег, какого хуя ты такой распиздяй?
- {
- unsigned char S[N];
- KSA(key, S);
- PRGA(S, plaintext, ciphertext);
- return 0;
- }
- int main(int argc, char *argv[])
- {
- // кроучи хуй знает зачем ара 6 утра помоги мне как же я з а е б а л с я
- char str[256];
- FILE *LeFinale = fopen("output.txt", "w+a");
- char kostil[] = "-m";
- if (argc == 3 )
- {
- unsigned char *ciphertext = malloc(sizeof(int) * strlen(argv[2]));
- // printf("One %s\n", argv[1]);
- // printf("Two %s\n", argv[2]);
- if (strcmp(argv[1], kostil) == 0)
- {
- RC4(argv[1], argv[2], ciphertext);
- for(size_t i = 0, len = strlen(argv[2]); i < len; i++)
- {
- putc(ciphertext[i], LeFinale);
- }
- fclose(LeFinale);
- //printf("%02hhX", ciphertext[i]);
- }
- else
- {
- // printf("%s", argv[1]);
- printf("ERROR! Wrong argument\n");
- }
- }
- else
- {
- printf("No arguments has been found.\nEnter text.\n");
- scanf( "%s", str);
- unsigned char *ciphertext = malloc(sizeof(int) * strlen(str));
- argv[1] = "-m";// ДА ЭТО ЕБУЧИЙ КОСТЫЛЬ НЕ СМОТРИ
- argv[2] = str;
- RC4(argv[1], argv[2], ciphertext);
- for(size_t i = 0, len = strlen(argv[2]); i < len; i++)
- {
- putc(ciphertext[i], LeFinale);
- }
- fputc('\n', LeFinale);
- for(size_t i = 0, len = strlen(argv[2]); i < len; i++)
- {
- putc(str[i], LeFinale);
- }
- putc("\n", LeFinale);
- RC4(argv[1], ciphertext, ciphertext);
- for(size_t i = 0, len = strlen(argv[2]); i < len; i++)
- {
- putc(ciphertext[i], LeFinale);
- }
- //fprintf(LeFinale, str);
- for(size_t i = 0, len = strlen(argv[2]); i < len; i++)
- {
- putc(str[i], LeFinale);
- }
- fclose(LeFinale);
- printf("%s", str);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment