diff --git a/year4/semester2/CT437/exam b/year4/semester2/CT437/exam new file mode 100644 index 00000000..f2252899 --- /dev/null +++ b/year4/semester2/CT437/exam @@ -0,0 +1,3 @@ +- always question about rsa and diffie helman +- don't expecct any diffie helman calculations on the exam, that would be ridiciulous + diff --git a/year4/semester2/CT437/materials/code/lfsr.c b/year4/semester2/CT437/materials/code/lfsr.c new file mode 100644 index 00000000..cb66250f --- /dev/null +++ b/year4/semester2/CT437/materials/code/lfsr.c @@ -0,0 +1,55 @@ +// +// Example for a 16-bit NFLSR +// + +#include +#include +#include + +#define LFSR_SIZE 16 +#define DEFAULT_START_STATE 0xACE1 // Default initial state for NLFSR + +uint16_t lfsr; +uint8_t used[65535]; + +uint8_t non_linear_feedback(uint16_t state) { + // Example non-linear function: XOR of specific bits and AND of others + uint8_t bit1 = (state >> 0) & 1; + uint8_t bit2 = (state >> 2) & 1; + uint8_t bit3 = (state >> 3) & 1; + uint8_t bit4 = (state >> 5) & 1; + uint8_t bit5 = (state >> 9) & 1; + return (bit1 ^ bit2 ^ bit3 ^ bit4 ^ bit5); +} + +uint8_t clock_and_shift_lfsr() { + uint8_t ret = lfsr & 1; + uint8_t new_bit = non_linear_feedback(lfsr); + lfsr = (lfsr >> 1) | (new_bit << (LFSR_SIZE - 1)); + + return ret; +} + +int main() { + uint16_t input; + uint16_t cycle = 0; + memset(used, sizeof(used), 0); + + printf("Enter IV for LFSR: "); scanf("%hd", &input); + input = input & 0xFFFF; + lfsr = input; + + while (1) { + cycle++; + printf("%d", clock_and_shift_lfsr()); + if (used[lfsr] > 0) + break; + else + used[lfsr] = 1; + // printf("%d\n", nlfsr); + } + + printf("\nCycle length: %d bits.\n", cycle); + return 0; +} + diff --git a/year4/semester2/CT437/materials/code/nlfsr.c b/year4/semester2/CT437/materials/code/nlfsr.c new file mode 100644 index 00000000..1d4f5f21 --- /dev/null +++ b/year4/semester2/CT437/materials/code/nlfsr.c @@ -0,0 +1,55 @@ +// +// Example for a 16-bit NFLSR +// + +#include +#include +#include + +#define NLFSR_SIZE 16 +#define DEFAULT_START_STATE 0xACE1 // Default initial state for NLFSR + +uint16_t nlfsr; +uint8_t used[65535]; + +uint8_t non_linear_feedback(uint16_t state) { + // Example non-linear function: XOR of specific bits and AND of others + uint8_t bit1 = (state >> 0) & 1; + uint8_t bit2 = (state >> 2) & 1; + uint8_t bit3 = (state >> 3) & 1; + uint8_t bit4 = (state >> 5) & 1; + uint8_t bit5 = (state >> 9) & 1; + return (bit1 ^ bit2) | (bit3 & bit4) ^ bit5; +} + +uint8_t clock_and_shift_nlfsr() { + uint8_t ret = nlfsr & 1; + uint8_t new_bit = non_linear_feedback(nlfsr); + nlfsr = (nlfsr >> 1) | (new_bit << (NLFSR_SIZE - 1)); + + return ret; +} + +int main() { + uint16_t input; + uint16_t cycle = 0; + memset(used, sizeof(used), 0); + + printf("Enter IV for NLFSR: "); scanf("%hd", &input); + input = input & 0xFFFF; + nlfsr = input; + + while (1) { + cycle++; + printf("%d", clock_and_shift_nlfsr()); + if (used[nlfsr] > 0) + break; + else + used[nlfsr] = 1; + // printf("%d\n", nlfsr); + } + + printf("\nCycle length: %d bits.\n", cycle); + return 0; +} + diff --git a/year4/semester2/CT437/materials/code/rc4.c b/year4/semester2/CT437/materials/code/rc4.c new file mode 100644 index 00000000..449c1fc7 --- /dev/null +++ b/year4/semester2/CT437/materials/code/rc4.c @@ -0,0 +1,67 @@ +// +// Example implementation of RC4 +// + +#include +#include +#include + +#define A_LEN 256 +#define SWAP(a, b) { uint8_t temp = a; a = b; b = temp; } + +void rc4_init(uint8_t *key, uint8_t *S, int key_length) { + int i, j = 0; + for (i = 0; i < 256; i++) { + S[i] = i; + } + for (i = 0; i < 256; i++) { + j = (j + S[i] + key[i % key_length]) % 256; + SWAP(S[i], S[j]); + } +} + +void rc4_generate_keystream(uint8_t *S, uint8_t *keystream, int length) { + int i = 0, j = 0, k; + for (k = 0; k < length; k++) { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + SWAP(S[i], S[j]); + keystream[k] = S[(S[i] + S[j]) % 256]; + } +} + +void rc4_encrypt_decrypt(uint8_t *data, uint8_t *keystream, int length) { + for (int i = 0; i < length; i++) { + data[i] ^= keystream[i]; + } +} + +int main() { + uint8_t key[A_LEN]; + uint8_t S[A_LEN]; + uint8_t data[A_LEN]; + int data_length; + uint8_t keystream[A_LEN]; + + printf("Enter key: "); scanf("%s", key); + printf("Enter plaintext: "); scanf("%s", data); + data_length = strlen((char *)data); + + rc4_init(key, S, strlen((char *)key)); + rc4_generate_keystream(S, keystream, data_length); + rc4_encrypt_decrypt(data, keystream, data_length); + + printf("Encrypted: "); + for (int i = 0; i < data_length; i++) { + printf("%02X ", data[i]); + } + printf("\n"); + + // Decrypting the data + rc4_encrypt_decrypt(data, keystream, data_length); + + printf("Decrypted: %s\n", data); + + return 0; +} + diff --git a/year4/semester2/CT437/materials/ct437_06 - Hash Cracking and Rainbow Tables.pdf b/year4/semester2/CT437/materials/ct437_06 - Hash Cracking and Rainbow Tables.pdf new file mode 100644 index 00000000..b54c0b6a Binary files /dev/null and b/year4/semester2/CT437/materials/ct437_06 - Hash Cracking and Rainbow Tables.pdf differ diff --git a/year4/semester2/CT437/materials/ct437_06 - Public Key Cryptography.pdf b/year4/semester2/CT437/materials/ct437_06 - Public Key Cryptography.pdf new file mode 100644 index 00000000..d40706a2 Binary files /dev/null and b/year4/semester2/CT437/materials/ct437_06 - Public Key Cryptography.pdf differ