-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.java
More file actions
69 lines (57 loc) · 1.69 KB
/
encryption.java
File metadata and controls
69 lines (57 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# java encryption
package szyfrowanie;
public class Szyfrowanie {
public static int numer(char literka)
{
return (int)literka-64;
}
public static char[]przepisz(String napis)
{
char[]t=new char[napis.length()];
for (int i = 0; i < t.length; i++) {
t[i]=napis.charAt(i);
}
return t;
}
public static char[]przepiszKlucz(String napis, String klucz){
char[]t=new char[napis.length()];
for (int i = 0; i < t.length; i++) {
t[i]=klucz.charAt(i%klucz.length());
}
return t;
}
public static void pokaz(char []t)
{
for (int i = 0; i < t.length; i++) {
System.out.print(t[i]+" ");
}
System.out.println("");
}
public static char[]szyfrowanie(String napis, String klucz)
{
char []tNapisz= przepisz(napis);
char []tKlucz= przepiszKlucz(napis, klucz);
char []t=new char[napis.length()];
for (int i = 0; i < tNapisz.length; i++) {
int kodAscii=(int)tNapisz[i];
int nr=numer(tKlucz[i]);
kodAscii+=nr;
t[i]=(char)kodAscii;
//sprawdz numer literki
}
return t;
}
public static void main(String[] args) {
/*
Podaj klucz i napis który chcesz nim zaszyfrować.
*/
String klucz="WODA";
String napis="You are welcome!";
char []tNapisz= przepisz(napis);
char []tKlucz= przepiszKlucz(napis, klucz);
System.out.println("Orginał: ");
pokaz(tNapisz);
System.out.println("Szyfr: ");
pokaz(tKlucz);
}
}