1 / 7

Simple encryption

Simple encryption. Introduction to Computers and Programming NCTU , Fall 2012 07/01/2013. Property of XOR. A ⊕ B = C C ⊕ B = A This property can be used in encryption: Think of A as original file B is password C is encrypted file

nickan
Download Presentation

Simple encryption

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simple encryption Introduction to Computers and Programming NCTU, Fall 2012 07/01/2013

  2. Property of XOR • A ⊕ B = C • C ⊕ B = A • This property can be used in encryption: • Think of A as original file • B is password • C is encrypted file • So, to decrypt a file, you just need to encrypt it with same password! 1100 1001 ⊕ 0101 1100 1001 0101 ⊕ 0101 1100 1100 1001

  3. XOR encryption (1/3) input.txt: Password:

  4. XOR encryption (2/3) • While (it is not end of file) { • Read inByte from input • outByte = inByte ^ passwordByte • Write outByte to output • Rotate passwordByte • } passwordByte: q w e r t y

  5. XOR encryption (3/3) ⊕ Output: =

  6. Practice • Implement XOR encryption • Your program should ask user for: • Name of input file (max 64 characters) • Name of output file (max 64 characters) • Password (max 64 characters) • Try to catch runtime errors that can occur: • Invalid filename • File does not exist • Empty password • etc.

  7. Example Encrypt Decrypt

More Related