aboutsummaryrefslogtreecommitdiff
path: root/encrypt_decoy.c
diff options
context:
space:
mode:
authorn0p <0x90@n0p.cc>2017-10-17 20:31:59 +0200
committern0p <0x90@n0p.cc>2017-10-17 20:31:59 +0200
commitec17df90f18c0e98c46986b8b0dfb6854cfc8a42 (patch)
tree9732747f35d46bc41bf9c65860d04a194e8695b6 /encrypt_decoy.c
downloadLostKey-ec17df90f18c0e98c46986b8b0dfb6854cfc8a42.tar.gz
LostKey-ec17df90f18c0e98c46986b8b0dfb6854cfc8a42.zip
Diffstat (limited to 'encrypt_decoy.c')
-rw-r--r--encrypt_decoy.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/encrypt_decoy.c b/encrypt_decoy.c
new file mode 100644
index 0000000..3cde750
--- /dev/null
+++ b/encrypt_decoy.c
@@ -0,0 +1,80 @@
+/*
+ * gcc encrypt_decoy.c -lcrypto
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "openssl/aes.h"
+
+int main() {
+ AES_KEY enc_key;
+
+ unsigned char plain[80] =
+ "Oh my, there's nothing here... Move along, but don't fall off the "
+ "edge!\0",
+ keys[4][16], cipher[4][80];
+
+ // Getting 4 random 128 bit keys.
+ int fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1) {
+ exit(-1);
+ }
+
+ for (int i = 0; i < 4; i++) {
+ if (read(fd, keys[i], 16) != 16) {
+ exit(-1);
+ }
+ }
+
+ close(fd);
+
+ // Encrypting the plain text with the 4 keys to 4 cipher texts.
+ for (int i = 0; i < 4; i++) {
+ AES_set_encrypt_key(keys[i], 128, &enc_key);
+
+ for (int j = 0; j < 5; j++) {
+ AES_encrypt(plain + 16 * j, cipher[i] + 16 * j, &enc_key);
+ }
+ }
+
+ // PP the key for copy & paste to the challenge source.
+ for (int i = 0; i < 4; i++) {
+ if (i == 0) {
+ printf("static unsigned char decoy_keys[4][16] = {{");
+ } else {
+ printf(" {");
+ }
+
+ for (int j = 0; j < 16; j++) {
+ if (j == 15) {
+ printf("'\\x%02X'", keys[i][j]);
+ } else {
+ printf("'\\x%02X', ", keys[i][j]);
+ }
+ }
+
+ if (i == 3) {
+ printf("}};\n");
+ } else {
+ printf("},\n");
+ }
+ }
+
+ // PP the cipher texts.
+ for (int i = 0; i < 4; i++) {
+ printf("static const unsigned char cipher[80] = {");
+
+ for (int j = 0; j < 80; j++) {
+ if (j == 79) {
+ printf("'\\x%02X'};\n", cipher[i][j]);
+ } else {
+ printf("'\\x%02X', ", cipher[i][j]);
+ }
+ }
+ }
+
+ return 0;
+} \ No newline at end of file