Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 4307 - Vigenére titkosítás és dekódolás - Bíró: 20 pont
- #include<stdio.h>
- int main() {
- int kod=0,hossz=0,i=0,j=0;
- char kulcs[27],szo[201];
- FILE *f;
- f=fopen("be.txt","r");
- while(!feof(f)) {
- fscanf(f,"%d",&kod);
- fscanf(f,"%d",&hossz);
- fscanf(f,"%s",kulcs);
- fscanf(f,"%s",szo);
- }
- if (kod==1) { //kódolás
- while(szo[i]!='\0') {
- if (j==hossz) {
- j=0;
- }
- if ((szo[i]-97)+(kulcs[j]-65)<=25) {
- szo[i]=szo[i]+(kulcs[j]-65);
- } else {
- szo[i]=(szo[i]+(kulcs[j]-65))-26;
- }
- i++;
- j++;
- }
- f=fopen("ki.txt","w");
- fprintf(f,"%s\n",szo);
- fclose(f);
- } else if (kod==2) { //dekódolás
- while(szo[i]!='\0') {
- if (j==hossz) {
- j=0;
- }
- if ((szo[i]-97)-(kulcs[j]-65)>=0) {
- szo[i]=szo[i]-(kulcs[j]-65);
- } else {
- szo[i]=(szo[i]-(kulcs[j]-65))+26;
- }
- i++;
- j++;
- }
- f=fopen("ki.txt","w");
- fprintf(f,"%s\n",szo);
- fclose(f);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment