Cryptography.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesThe Mighty Mod.
Character and String definitions, algorithms, library functions Characters and Strings.
 Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key.  He would take each letter.
A file reminder Files are used to store data and information They are manipulated through a pointer to FILE (FILE *) This pointer is returned when opening.
Tools for Text Review. Algorithms The heart of computer science Definition: A finite sequence of instructions with the properties that –Each instruction.
CMPE13 Cyrus Bazeghi Hands on with Functions and IO.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.
Programming Review: Functions, pointers and strings.
What does this program do ? #include int main(int argc, char* argv[]) { int i; printf("%d arguments\n", argc); for(i = 0; i < argc; i++) printf(" %d: %s\n",
Exercise 10 Review: pointers, strings and recursion.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Cryptanalysis of the Vigenere Cipher Using Signatures and Scrawls To break a Vigenere cipher you need to know the keyword length. – The Kasiski and Friedman.
Cryptography Programming Lab
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Section 2.1: Shift Ciphers and Modular Arithmetic The purpose of this section is to learn about modular arithmetic, which is one of the fundamental mathematical.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Computer Security coursework 2 Dr Alexei Vernitski.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Website protection Convert page source to a human- unreadable code.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Command Line Arguments plus Variable-Length Arrays Systems Programming.
File ▪ File – Unit of logical storage – Aid in manipulating exact sector of file data ▪ Abstract view of secondary physical storage devices ▪ Without files.
CS50 Section 2 21 September 2015 Sam Green ’17 (646)
CS50 Week 2. RESOURCES Office hours ( Lecture videos, slides, source code, and notes (
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
File IO and command line input CSE 2451 Rong Shi.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
Fall 2004CS-183 Dr. Mark L. Hornick 1 C++ Arrays C++ (like Java) supports the concept of collections – mechanisms to sort and manipulate many instances.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Recursion.
Vigenére Cipher Kimberly Chiffens & Maria Jannelli.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Substitution Ciphers Reference –Matt Bishop, Computer Security, Addison Wesley, 2003.
LAB#3 CLASSICAL ENCRYPTION CPIT 425. This diagram is taken from Dr.Omaima slides.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Command Line Arguments
Command line arguments
Command Line Arguments
Strings string: An object storing a sequence of text characters.
FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Five-minute starter task
Encryption and Decryption
sscanf()- string scan function
Simple Encryption- Lesson 5
Fun with Cryptography The Science of Secrecy.
Strings and Pointer Arrays
Homework Reading Programming Assignments Finish K&R Chapter 1
String manipulation string.h library
Strings string: An object storing a sequence of text characters.
EPSII 59:006 Spring 2004.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Presentation transcript:

Cryptography

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

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

Assistance <ctype.h> library look here: http://www.cplusplus.com/reference/cctype/ 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

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

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

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

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

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