-
Notifications
You must be signed in to change notification settings - Fork 0
/
repeatingKeyXOR.c
37 lines (32 loc) · 935 Bytes
/
repeatingKeyXOR.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018 (c), Neven Sajko. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the
// LICENSE file.
#include <stdio.h> // fprintf fread feof ungetc
#include <stdlib.h> // malloc
#include <string.h> // strlen
#include "bitstringDistance/bitstringDistance.h"
#include "buffer/buffer.h"
#include "encoding/encoding.h"
#include "sizeofMacros.h"
#include "xor/xor.h"
static void
f(const char *plaintext, const char *key) {
buffer plainBuf, keyBuf, *encBuf, *outBuf;
plainBuf.b = (unsigned char *)plaintext;
plainBuf.l = strlen(plaintext);
keyBuf.b = (unsigned char *)key;
keyBuf.l = strlen(key);
encBuf = repeatingXorAlloc(&plainBuf, &keyBuf);
outBuf = base64EncodeAlloc(encBuf);
FWRITE(outBuf->b, outBuf->l, stdout);
bufferFree(outBuf);
bufferFree(encBuf);
}
int
main(int argc, char *argv[]) {
if (argc != 3) {
return 1;
}
f(argv[1], argv[2]);
return 0;
}