-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
void lower(char tekst[]) { | ||
/* | ||
* Funkcja zamienia duże litery na małe | ||
*/ | ||
int i = 0; | ||
while (tekst[i]!='\0') { | ||
if (tekst[i] == ' ') ; | ||
else if ((int)tekst[i] > 64 && (int)tekst[i] < 90) | ||
tekst[i] = (char)((int)tekst[i] + 32); | ||
i++; | ||
} | ||
} | ||
|
||
|
||
// A-Z = ASCII 65-90; a-z = ASCII 97-122; a-A = 32; | ||
void szyfruj(char tekst[], int klucz) { | ||
int i = 0; | ||
klucz = klucz % 26; // przesuniecie znaku o calkowita wielokrotnosc 26 nie zmienia kodowanego znaku! | ||
while (tekst[i]!='\0') { | ||
if (tekst[i] == ' ') ; | ||
else if ((int)tekst[i] + klucz > 122) // ograniczenie, aby nie przekroczyc zakresu 122 w ASCII | ||
tekst[i] = (char)((int)tekst[i] + klucz - 26); | ||
else | ||
tekst[i] = (char)((int)tekst[i] + klucz); | ||
i++; | ||
} | ||
} | ||
|
||
void deszyfruj(char tekst[], int klucz) { | ||
int i = 0; | ||
klucz = klucz%26; | ||
while (tekst[i]!='\0') { | ||
if (tekst[i] == ' ') ; | ||
else if ((int)tekst[i] - klucz < 97) | ||
tekst[i] = (char)((int)tekst[i] - klucz + 26); | ||
else | ||
tekst[i] = (char)((int)tekst[i] - klucz); | ||
i++; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
#define MAKS 100 | ||
string tekst; | ||
int klucz; | ||
cout << "Podaj tekst: " << endl; | ||
cin >> tekst; | ||
cout << "Podaj klucz: "; | ||
cin >> klucz; | ||
cout << tekst; | ||
//szyfruj(tekst, klucz); | ||
//cout << "Szyfrogram:" << endl << tekst << endl; | ||
//deszyfruj(tekst, klucz); | ||
//cout << "Deszyfr:" << endl << tekst << endl; | ||
// getchar(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
def szyfruj(tekst, klucz): | ||
i = 0 | ||
for l1 in tekst: | ||
print ord(l1) - 96 | ||
if i > len(klucz) - 1: | ||
i = 0 | ||
print ord(klucz[i]) - 96 | ||
znak = (ord(l1) - 96 + ord(klucz[i]) - 96) | ||
if znak > 26: | ||
znak -= 26 | ||
print znak | ||
i += 1 | ||
|
||
|
||
def main(args): | ||
tekst = raw_input("Podaj tekst: ") | ||
klucz = raw_input("Podaj klucz: ") | ||
szyfruj(tekst, klucz) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
sys.exit(main(sys.argv)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
def szyfruj_vigenere(tekst, klucz): | ||
szyfrogram = '' | ||
i = 0 | ||
for litera in tekst: | ||
if i > len(klucz) - 1: | ||
i = 0 | ||
wartosc3 = ord(litera.upper()) + ord(klucz[i].upper()) - 64 | ||
if wartosc3 > 90: | ||
wartosc3 -= 26 | ||
szyfrogram += chr(wartosc3) | ||
i += 1 | ||
return szyfrogram | ||
|
||
|
||
def main(args): | ||
tekst = raw_input("Podaj tekst: ") | ||
klucz = raw_input("Podaj klucz: ") | ||
print(szyfruj_vigenere(tekst, klucz)) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
sys.exit(main(sys.argv)) |