1006 - cypercode[i = alpha2code cypertext[i c pos = i...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> # using namespace std; u int key; int pos; char plaintext[80]; char plaincode[80]; char cypercode[80]; char cypertext[80]; c char alpha2code(char c){ if(c == '_') return 0; if(c == '.') return 27; return c-'a' + 1; } char code2alpha(char code){ if(code ==0) return '_'; if(code == 27) return '.'; return code -1 + 'a'; } int fun(){ int i; int t; for(i=0; cypertext[i] ; i++){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cypercode[i] = alpha2code( cypertext[i] ); c } pos = i; for(i=0;i<pos;i++){ plaincode[key * i % pos] = (cypercode[i] + i) % 28; } for(i=0; i<pos;i++){ plaintext[i] = code2alpha( plaincode[i] ); } plaintext[pos] = 0; cout<<plaintext<<endl; } int main(){ cin>>key; while(key ){ cin>>cypertext; fun(); cin>>key; } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Ask a homework question - tutors are online