Last active
December 15, 2015 10:19
-
-
Save ql-owo-lp/5245068 to your computer and use it in GitHub Desktop.
for CIS 644 Lab 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<HTML> | |
<HEAD> | |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> | |
<META NAME="hexdata" CONTENT="GHex export to HTML"> | |
</HEAD> | |
<BODY> | |
<TABLE BORDER="0" CELLSPACING="0" WIDTH="100%"> | |
<TR> | |
<TD WIDTH="33%"> | |
| |
</TD> | |
<TD WIDTH="33%" ALIGN="CENTER"> | |
ciphertext: | |
</TD> | |
<TD WIDTH="33%" ALIGN="RIGHT"> | |
| |
</TD> | |
</TR> | |
</TABLE> | |
<CENTER> | |
<TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2"> | |
<TR> | |
<TD> | |
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"> | |
<TR> | |
<TD> | |
<PRE>00000000</PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE>00000011</PRE> | |
</TD> | |
</TR> | |
</TABLE> | |
</TD> | |
<TD> | |
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"> | |
<TR> | |
<TD> | |
<PRE>8d 20 e5 05 6a 8d 24 d0 46 2c e7 4e 49 04 c1 b5 13</PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE>e1 0d 1d f4 a2 ef 2a d4 54 0f ae 1c a0 aa f9 </PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE> | |
</TD> | |
</TR> | |
</TABLE> | |
</TD> | |
<TD> | |
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"> | |
<TR> | |
<TD> | |
<PRE>. ..j.$.F,.NI....</PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE>......*.T......</PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
<TR> | |
<TD> | |
<PRE></PRE></TD> | |
</TR> | |
</TD> | |
</TR> | |
</TABLE> | |
</TABLE> | |
</CENTER> | |
<HR WIDTH="100%">Hex dump generated by <B>gtkhex-1.0</B> | |
</BODY> | |
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For AES encryption/decryption lab. -> CIS 644 / Sp13 -> Kevin Wang | |
*/ | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <openssl/evp.h> | |
int main () { | |
read_words("words.txt"); | |
return 0; | |
} | |
int do_crypt1(char *_key) | |
{ | |
unsigned char outbuf[1024]; | |
int outlen, tmplen, i; | |
// init key and iv | |
unsigned char key[16]; | |
unsigned char iv[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
char intext[] = "This is a top secret."; | |
strncpy((char *)key, _key, 16); | |
// append space | |
for (i=15;i>0;i--) { | |
if (key[i]==0) | |
key[i]=' '; | |
} | |
EVP_CIPHER_CTX ctx; | |
FILE *out; | |
EVP_CIPHER_CTX_init(&ctx); | |
EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, iv); | |
if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext))) | |
{ | |
/* Error */ | |
return 0; | |
} | |
if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) | |
{ | |
/* Error */ | |
return 0; | |
} | |
outlen += tmplen; | |
EVP_CIPHER_CTX_cleanup(&ctx); | |
out = fopen("test", "wb"); | |
fwrite(outbuf, 1, outlen, out); | |
fclose(out); | |
return 1; | |
} | |
int do_crypt(char *_key) | |
{ | |
unsigned char inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; | |
int inlen, outlen, tmplen, do_encrypt=0, i; | |
FILE *in, *out; | |
unsigned char key[16]; | |
unsigned char iv[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
unsigned char intext[] = "This is a top secret."; | |
EVP_CIPHER_CTX ctx; | |
in = fopen ("ciphertext", "rb"); | |
strncpy((char *)key, _key, 16); | |
// append space | |
for (i=15;i>0;i--) { | |
if (key[i]==0 || key[i]==13 || key[i]==10 || key[i]=='\0') | |
key[i]=' '; | |
} | |
/* Don't set key or IV because we will modify the parameters */ | |
EVP_CIPHER_CTX_init(&ctx); | |
EVP_CipherInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, iv, do_encrypt); | |
for(;;) | |
{ | |
inlen = fread(inbuf, 1, 1024, in); | |
if(inlen <= 0) break; | |
if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen)) | |
{ | |
/* Error */ | |
EVP_CIPHER_CTX_cleanup(&ctx); | |
fclose(in); | |
return 0; | |
} | |
} | |
fclose(in); | |
if(!EVP_CipherFinal_ex(&ctx, outbuf + outlen, &tmplen)) | |
{ | |
/* Error */ | |
EVP_CIPHER_CTX_cleanup(&ctx); | |
return 0; | |
} | |
outlen += tmplen; | |
EVP_CIPHER_CTX_cleanup(&ctx); | |
out = fopen("test1", "wt"); | |
fwrite(outbuf, 1, outlen, out); | |
fclose(out); | |
// strcmp(outbuf, intext) doesn't work | |
for (i=0;i<21;i++) { | |
if (*(outbuf+i) != intext[i]) return 0; | |
} | |
return 1; | |
} | |
// read key (words) from specific file | |
int read_words (char * file) { | |
FILE *fr; | |
fr = fopen (file, "rt"); | |
char word[16]; // at most 16 characters | |
while(fgets(word, 16, fr) != NULL) | |
{ | |
if (do_crypt(word)) | |
printf("Found! key is %s", word); | |
} | |
fclose(fr); /* close the file prior to exiting the routine */ | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INC=/usr/local/ssl/include/ | |
LIB=/usr/local/ssl/lib/ | |
all: | |
gcc -I$(INC) -L$(LIB) -o enc Crypto-lab5-cracker.c -lcrypto |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment