#include <stdio.h> void encrypt(int shift); int main(void) { int shift; int decOrEnc; printf("Amount of shifts: "); scanf("%d", &shift); if (shift < 0) { printf("Bad Input."); return 0; } printf("Type 1 to encrypt or 0 to decrypt: "); scanf("%d", &decOrEnc); if (decOrEnc != 0 && decOrEnc !=1) { printf("Bad Input."); return 0; } while(getchar() != '\n'); if (decOrEnc == 1) encrypt(shift); else { shift = -1 * shift; encrypt(shift); } return 0; } void encrypt(int shift) { char ch; printf("Please enter a string: "); ch = getchar(); while(ch != '\n') { if (ch == ' ') putchar(ch); else { if(shift == 1) putchar(ch + shift); else putchar(ch - shift); } ch = getchar(); } putchar(ch); }
Khamis, Mei 16, 2013
C : Caesar Cipher
Label:
C/C++,
Pengaturcaraan,
Sekuriti
Langgan:
Catat Ulasan (Atom)
0 ulasan:
Catat Ulasan
Selamat datang ke 0x2013LΣΣT. Sekiranya anda mempunyai persoalan, pandangan, permintaan, bantuan, cadangan dan sebagainya. Tinggalkan pesanan anda ke dalam kotak komen. Terima kasih !
- http://0x2013.blogspot.com -