Zig Zag Cryptography

download Zig Zag Cryptography

If you can't read please download the document

description

Created By: Andysah Putra Utama Siahaan, S.Kom

Transcript of Zig Zag Cryptography

DESCRIPTION OF RAIL FENCEThe plaintext is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. When we reach the top rail, the message is written downwards again until the whole plaintext is written out. The message is thenreadoffinrows.

ZIG ZAG CRYPTOGRAPHY3

D N A1 2 3 4

H Y S5 6 7

2

A

1

CreatedBy:Andysah,Zara, Sany,Sri,Zuhri

LINKED LISTA B C

Information

Pointer

ADDING THE NODEprocedureAddNode(varFirst,Last:pNode;ch:char;Column,Row:byte); var Temp:pNode; begin new(Temp); iford(ch)=32then Temp^.Space:=true else Temp^.Space:=false; Temp^.Content:=ch; Temp^.Column:=Column; Temp^.Row:=Row; ifFirst=nilthen First:=Temp else Last^.Next:=Temp; Last:=Temp; end;

ENCRYPTIONAlgorithm: Makealineartree Recordthecolumn&row Getthedatafromtheplain textaccordingtotherow position Returntheciphertext

HereWeGo!!!

LINEAR TREED N A Y S A H

PLAIN:ANDYSAH CIPHER:DHNYAAS

EXPLANATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

Treecontainsofcolumns& rows.

INFORMATION RECORDtype pNode=^tNode; tNode=record Content:char; Column:byte; Row:byte; Next:pNode; end;

BUILD THE TREEprocedureBuildTree(varFirst,Last:pNode;s:string); var i:byte; Column,Row:byte; isUp:boolean; begin isUp:=true; Column:=1;Row:=1; fori:=1tolength(s)do begin AddNode(First,Last,s[i],Column,Row); inc(Column); if(isUp)and(RowCharacter1 Data7:X,7,3=>Character2 Data2:X,2,2=>Character3 Data4:X,4,2=>Character4 Data6:X,6,2=>Character5 Data1:X,1,1=>Character6 Data5:X,5,1=>Character7

Sorttherowindescending order&thecolumnatthe samerowsinascending.

WE'VE GOT THE RULETemporaryText:XXXXXXX TextLength:7

X 1 3

X 2

X 3

X 4 2

X 5

X 6 1

X 7

CipherText:DHNYAAS DH:=3rd ,NYA:=2nd AS:=1st

RE-PLACETemporaryText:XXXXXXX TextLength:7

D 1 3

H 2

N 3

Y 4 2

A 5

A 6 1

S 7

CipherText:DHNYAAS DH:=3rd ,NYA:=2nd AS:=1st

RE-TREE POSITION3

D X X1 2 3 4

H X X5 6 7

2

X

1

The3 Row Cipher:=DH

r d

RE-TREE POSITION3

D N X1 2 3 4

H Y X5 6 7

2

A

1

The2 Row Cipher:=DH+NYA

n d

RE-TREE POSITION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The1 Row Cipher:=DH+NYA+AS

s t

TREE TO TEXTData1:A,1,1 Data2:N,2,2 Data3:D,3,3 Data4:Y,4,2 Data5:S,5,1 Data6:A,6,2 Data7:H,7,3

Getthecharacterforthe firsttolastcolumn.Column isalwayssorted.

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The1 Column Plain:=A

s t

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The2 Column Plain:=AN

n d

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The3 Column Plain:=AND

r d

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The4 Column Plain:=ANDY

t h

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The5 Column Plain:=ANDYS

t h

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The6 Column Plain:=ANDYSA

t h

ILLUSTRATION3

D N A1 2 3 4

H Y S5 6 7

2

A

1

The7 Column Plain:=ANDYSAH

t h

PLAIN TEXT FUNCTIONfunctionToPlainText(Node:pNode):string; var Result:string; Temp:pNode; begin Temp:=Node;k:=1; fori:=Stepdownto1do begin forj:=1tolength(PlainText)do begin ifTemp^.Row=ithen begin Temp^.Content:=CipherText[k]; inc(k); End;Temp:=Temp^.Next; End;Temp:=Node; end; Result:=PlainText; fori:=1tolength(PlainText)do begin Result[Temp^.Column]:=Temp^.Content; Temp:=Temp^.Next; end; ToPlainText:=Result; end;

THANK YOU FOR WATCHING, BYE !!!