summaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-08-04 19:24:17 +0200
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:25 +0100
commit4e0e29f48f797206a21aa5ba7855ffde72e85cf9 (patch)
tree951795c82c357aa9560f7b529f5b93e51554ed86 /lib/lib.c
parent11b2ff584c67cf85ebe2405f6a74ab2799736927 (diff)
completed set3, challenge 20
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 7c8beae..0e02726 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -555,4 +555,31 @@ int string_is_ecb_encrypted(char *string, int length_string, int blocksize)
return (count_equal_blocks(string, length_string, blocksize) > (length_string/blocksize));
}
+/**
+* split ciphertext in blocks of size blocksize
+ * @return returns an array of string of size with blocksize elements
+ */
+
+
+char **transpose_blocks(char *ciphertext, int blocksize, int length)
+{
+ char **blocks;
+ int i, j;
+ int number_blocks = length / blocksize;
+
+ blocks = malloc(blocksize*(sizeof(char*)));
+
+ for(i=0;i<blocksize;i++) {
+ blocks[i] = malloc(number_blocks+1);
+ }
+
+ for(j=0;j<blocksize;j++) {
+ for(i=0;i<number_blocks;i++) {
+ blocks[j][i] = ciphertext[(i*blocksize)+j];
+ }
+ }
+
+ return blocks;
+}
+