Javascript, Loops, and Encryption

Slides:



Advertisements
Similar presentations
ASCII stands for American Standard Code for Information Interchange
Advertisements

Fundamentals of Computer and programming in C
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Craig Schock, 2003 Binary Numbers Numbering Systems Counting Symbolic Bases Common Bases (10, 2, 8, 16) Representing Information Binary to Decimal Conversions.
EECC250 - Shaaban #1 lec #13 Winter HEX DEC CHR Ctrl 00 0NUL 01 1 SOH ^A 02 2STX ^B 03 3ETX ^C 04 4EOT ^D 05 5ENQ ^E 06 6ACK ^F 07 7BEL.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Digital Text Primer Prepared for: AIEA Roundtable on Digitization of Armenian Documents Saturday 7 October 2006, University of Geneva, Switzerland Roland.
Characters & Strings Lesson 1 CS1313 Spring Characters & Strings Lesson 1 Outline 1.Characters & Strings Lesson 1 Outline 2.Numeric Encoding of.
1 Data Representation Computer Organization Prof. H. Yoon DATA REPRESENTATION Data Types Complements Fixed Point Representations Floating Point Representations.
The character data type char
Chapter 7 Data Coding. Agenda Coding Code efficiency and conversion Compression/compaction Code encryption/decryption.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Digital Design: From Gates to Intelligent Machines
Decimal Binary Octal Hex
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
PHY281Variables operators and math functions Slide 1 More On Variables and Operators, And Maths Functions In this section we will learn more about variables.
Dept. of Computer Science Engineering Islamic Azad University of Mashhad 1 DATA REPRESENTATION Dept. of Computer Science Engineering Islamic Azad University.
2440: 211 Interactive Web Programming Expressions & Operators.
Informatics I101 February 25, 2003 John C. Paolillo, Instructor.
Postacademic Interuniversity Course in Information Technology – Module C1p1 Chapter 1 Evolution of Communication Networks.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Representing Information Digitally Bits and the “Why” of Bytes lawrence snyder.
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Regular Expression JavaScript Web Technology Derived from:
INTRODUCTION TO C C was developed by Dennis Ritchie at Bell laboratory in 1972 It is an upgrade version of languages B and BCPL.
Review Spatial Filters – Smooth – Blur – Low Pass Filter – Sharpen – High Pass Filter – Edge detection – Erosion – Dilation Other Pixel Filters – Thresholding.
1 Information Representation in Computer Lecture Nine.
CS 2130 Lecture 23 Data Types.
Systems Architecture, Fourth Edition 1 Data Representation Chapter 3.
Programming for GCSE Topic 2.2: Binary Representation T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science.
PRIMITIVE TYPES IN JAVA Primitive Types Operations on Primitive Types.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
4th Edition, Irv Englander
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Machine level representation of data Character representation
C Programming Language Review and Dissection
Chapter 3 Data Representation Text Characters
Digitizing Discrete Information
Characters Lesson Outline
Binary (Base-2) Numbers
DATA REPRESENTATION Data Types Complements Fixed Point Representations
JavaScript is a programming language designed for Web pages.
Chapter 2 Data Types and Representations
C++ Basics.
Computer Symbols
ASCII Character Codes nul soh stx etx eot 1 lf vt ff cr so
INFO/CSE 100, Spring 2005 Fluency in Information Technology
October 1 Programming Questions?
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Cosc 2P12 Week 2.
INFO/CSE 100, Spring 2006 Fluency in Information Technology
An introduction to UML 2 for modelling communications
Number Systems Lecture 2.
elementary programming
Text Encoding.
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Characters Lesson Outline
JavaScript Basics What is JavaScript?
Introduction to Computer Engineering
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Rayat Shikshan Sanstha’s S. M. Joshi College, Hadapsar
Text Representation ASCII Collating Sequence
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Keyboard Test Study Guide
Cosc 2P12 Week 2.
KEYBOARDING SKILLS NUMBER AND SYMBOL KEYS
X-Plane Commands and Datarefs TCP vs. UDP
Presentation transcript:

Javascript, Loops, and Encryption October 24, 2008

Today Reminder of what a for-loop looks like Crytoquotes The ASCII Table Converting characters to and from ASCII Programming encryption

For-loops For loops in javaScript allow for the repetition of blocks of code for (j = 1; j <= 10; j = j + 1) { document.write(“Hello\n”); } http://people.uncw.edu/guinnc/courses/Fall08/110/notes/day24_javascript7/hello.htm

Syntax of for-loops for ( initialization; continuation; next_iteration) { list_of_statements } Initialization: Set the iteration variable to its starting value x = 0; j = 1;

For-Loops: Continuation for ( initialization; continuation; next_iteration) { list_of_statements } Continuation: Test condition to see whether to execute the body of the loop. The test condition is a boolean expression If it is true, execute the list of statements Otherwise, go to the next line after the entire for-loop. J < 20 Total <= N.

For loops: Next Iteration for ( initialization; continuation; next_iteration) { list_of_statements } Next_iteration: Statements that are executed AFTER the list_of_statements are executed. Good programming practice: next_iteration should change the value of the iteration variable. j = j + 1 x++

Cryptoquotes A coded message where each letter has a substitute. FRA PIF XD FRA LIF THE CAT IN THE HAT

ASCII The American Standard Code for Information Interchange (ASCII)* is a standardized system for encoding characters numerically. It has several categories of characters: letters: upper case ('A' = 65 through 'Z' = 90); lower case ('a' = 97 through 'z' = 122); digits ('0' = 48 through '9' = 57); punctuation space = 32 through slash = 47; colon = 58 through at sign = 64; open square bracket = 91 through backquote = 96; open curly brace = 123 through tilde = 126; control characters, encoded as 0 through 31; also DEL (encoded as 127). * http://www.asciitable.com/

End Transmission Block ASCII Table #1 Code Char Kbd Name NUL Null 16 DLE Ctrl-P Data Line Escape 1 SOH Ctrl-A Start of Heading 17 DC1 Ctrl-Q Device Control 1 2 STX Ctrl-B Start of Text 18 DC2 Ctrl-R Device Control 2 3 ETX Ctrl-C End of Text 19 DC3 Ctrl-S Device Control 3 4 EOT Ctrl-D End of Transmission 20 DC4 Ctrl-T Device Control 4 5 ENQ Ctrl-E Enquiry 21 NAK Ctrl-U Negative Acknowledge 6 ACK Ctrl-F Acknowledge 22 SYN Ctrl-V Synchronous File 7 BEL Ctrl-G Ring Bell 23 ETB Ctrl-W End Transmission Block 8 BS Ctrl-H Backspace 24 CAN Ctrl-X Cancel 9 HT Ctrl-I Horizontal Tab 25 EM Ctrl-Y End of Medium 10 LF Ctrl-J Line Feed 26 SUB Ctrl-Z Substitute 11 VT Ctrl-K Vertical Tab 27 ESC Ctrl-Shift-K Escape 12 FF Ctrl-L Form Feed 28 FS Ctrl-Shift-L File Separator 13 CR Ctrl-M Carriage Return 29 GS Ctrl-Shift-M Group Separator 14 SO Ctrl-N Shift Out 30 RS Ctrl-Shift-N Record Separator 15 SI Ctrl-O Shift In 31 US Ctrl-Shift-O Unit Separator

ASCII Table #2 Code Char Name 32 Blank space 48 33 ! Exclamation point 33 ! Exclamation point 49 1 34 " Double quote 50 2 35 # Pound 51 3 36 $ Dollar sign 52 4 37 % Percent 53 5 38 & Ampersand 54 6 39 ' Single quote 55 7 40 ( Open parenthesis 56 8 41 ) Close parenthesis 57 9 42 * Asterisk 58 : Colon 43 + Plus 59 ; Semicolon 44 , Comma 60 < Less than 45 - Hyphen 61 = Equals 46 . Period 62 > Greater than 47 / Slash 63 ? Question mark

ASCII Table #3 Code Char Name 64 @ At 80 P 65 A 81 Q 66 B 82 R 67 C 83 68 D 84 T 69 E 85 U 70 F 86 V 71 G 87 W 72 H 88 X 73 I 89 Y 74 J 90 Z 75 K 91 [ Open square bracket 76 L 92 \ Backslash 77 M 93 ] Close square bracket 78 N 94 ^ Caret 79 O 95 _ Underscore

ASCII Table #4 Code Char Name 96 ` Accent grave 112 p 97 a 113 q 98 b 114 r 99 c 115 s 100 d 116 t 101 e 117 u 102 f 118 v 103 g 119 w 104 h 120 x 105 i 121 y 106 j 122 z 107 k 123 { Open curly brace 108 l 124 | Vertical bar 109 m 125 } Close curly brace 110 n 126 ~ Tilde 111 o 127 DEL Delete

Converting to and from ASCII in Javascript To find out the particular ASCII code of the first character in a string, s, var code = s.charCodeAt(0); To convert a number, code, to its ASCII-mapped character, var s = String.fromCharCode(code);

Doing some encryption and decription Let’s start with this file: Encrypt.htm Some steps: When the user hits “Encode”, put the plain text into the “Encoded” box. Now, when the user hits “Encode”, put the ASCII values of the plain text into Encoded. Now, add 1 to each of the ASCII values. Convert each modified ASCII value to its appropriate character and put the result in Encoded.

Now let’s go the other way Take the string in Encoded and decode it by subtracting 1 from each ASCII value.

Could we use a number besides 1? Try it. How can we make the code better? Even better?

Next Time How can we have the computer solve a cryptoquote where it doesn’t know the key?