Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cryptography.

Similar presentations


Presentation on theme: "Cryptography."— Presentation transcript:

1 Cryptography

2 Accepting arguments from command line
Main() function gets a new look int main(int argc, char *argv[]) int main(int argc, char **argv) argc – argument count argv – argument vector NB! If You don’t plan on accepting arguments, use void! 2015

3 Argc and argv properties
argc is always at least 1 or greater – depending on how many arguments were passed argv gives You access to all of the passed arguments. They’re stored as character arrays (strings) argv[0] contains the name of the program executed Argv’s first dimension length is argc (passed argument count) The second dimension length depends on the length of each string (argument) 2015

4 Assistance <ctype.h> library look here: ASCII table To convert strings to numbers you can use: sscanf() function from <stdio.h> library Some string conversion functions also available in <stdlib.h> library 2015

5 Lab task main requirements
The program must accept only the right amount of arguments from the command line. They must also be formatted correctly – if they’re not, display helper text. Program must be able to encrypt and decrypt how to run: ./programname -action cipher -d – decrypt -e – encrypt The cipher must correspond to the algorithm you’re using The text to encrypt / decrypt will be given inside of the program You must differentiate lower and upper case letters. Punctuation signs will be ignored. 2015

6 Lab task - Caesar It’s based on shifting. The cipher is the number of characters shifted ci = (pi + k) % 26 pi - original character ci - encrypted character k - cipher (shift amount) Program accepts action (encrypt or decrypt) and the cipher (shift count) from command line 2015

7 Example encryption a b c d e f g h i j k l m o p q r s t u v w x y z
Key: 3 (the alphabet is shifted by 3) n e.g: Original word: time Key: 3 t + 3 -> w i + 3 -> l m + 3 -> p e + 3 -> h Result: wlph e.g: Original word: Black tea Key: 7 B + 7 -> I t + 7 -> a l + 7 -> s e + 7 -> l a + 7 -> h a + 7 -> h c + 7 -> j k + 3 -> r Result: Tbza all 2015

8 Lab task - Vigenère Works based on shifting characters, cipher is a word ci = (pi + kj) % 26 pi - original character ci - encrypted character kj - character shift based on alphabetical position (e.g: a, A = 0; d, D = 3 e.t.c) Program accepts action (encrypt or decrypt) and the cipher (string to base shifting on) from command line The cipher must not differentiate lower or upper case character, however the text that will be encrypted must! 2015

9 Example encryption Text to be encrypted: Spiderpig Cipher: bcad
Original text S p i d e r g Cipher key b c a Key as a number 1 2 3 Encrypted text T f t l h 2015


Download ppt "Cryptography."

Similar presentations


Ads by Google