ExcepionsAsagidaki question of us wants to develop a cryptology algorithm algorithm.
and written into one class and a String value Messagio wants us to. yazamamizi isyor encryption method and password, and 2 other methods to resolve.
This algorithm seeks to create a class for the two sub-
tane'de ROS and XOR, tie rod from the String class, and again to convey a message in a sequence by taking the string value by mode and up to the value of the string value of unicod grilen wants us to improve.
URL for XOR is written into a class by using the XOR operator isyor ..
=========================================
encrypted messages
Define Message in a class can contain a text message
(a string) and provides two abstract methods void figure (String k) and void
`
decrypt (String k) where k and the key used to encrypt and decrypt the message-
Thurs Then define two subclasses that implement the following mechanisms
encryption / decryption:
ROT `n The key k and a string that represents a number n. The algorithm encrypts the text
by replacing each letter with the one that follows the n-bit
provisions (circle) in the collection of Unicode encoding. The de-encryption
is similar: each letter of the encrypted message
is replaced with the letter that precedes the n positions (movement
mind) the whole of Unicode encoding.
`
XOR key ke a string of arbitrary length. The encryption is done by running the
xor between text characters and the characters of the key. In
if the text is longer than the key, the characters
of the latter are used in a circular fashion. The decryption
is doing exactly the same procedure on the ciphertext. Finally
Write a main program test in which references to
type messages are assigned objects of the two subtypes. Then, try to
Prints the text of the message after it has been encrypted and decrypted.
===========================================
Cozum:
figure package;
/ **
Sinif ismimiz abstract messages yapiyoruz cunku Altindere olusturacak oldugmuz siniflarin degerlerini kullana bilmek icin.
* / public
Messaggio abstract class {protected String data
;
public Messaggio (String s) {
/ / String value we get another one, this string will be our secret post we
data = s;}
/ / abstract and below Create the sub-classes for use in classes. Public abstract void
cifra (String chiave);
public abstract void decifra (String chiave);
/ / where the toString () String values \u200b\u200beasily can access and print using the data value. Public String toString
() {return data;}}
======================
/ / sub-class package cifra
;
/ **
order to create here the lower class, upper class that is derived from the identifier of this class to know that we have to use the phrase exdeds
* / public class tie rod extends
Messaggio {
public Wheel (String s) {
/ / where super () statement we create an object with the top
call super (s);
} public void
cifra (String c) {
/ / The following string value received from the integera translate.
int n = Integer.parseInt (c);
/ / and char [] array of super draws data from the data of our class We transfer to the array.
char [] aa = data.toCharArray ();
for (int i = 0; i \u0026lt;aa.length; i + +)
/ / Here, the data in the array of character strings one by one until reaching an increase each receive unicode mode are recorded.
aa [i] = (char) (aa [i] + n% 65536);
/ / The following message is encrypted into the data, writing data.
data = new String (aa);}
/ / Below we use the method to resolve the message is encrypted. Public void
decifra (String c) {
/ / message and will seek to resolve and Integer'a sifremizi again converting.
int n = Integer.parseInt (c);
/ / This is the time to send and print the subtraction method of making Cifra.
n = 65536 - n;
cifra (Integer.toString (n));
}}
====================== ===
Program:
cifra package;
IngressoUscita.Console import;
public class {public static void Proof
main (String [] args)
/ / Here, Rod olsuturyoruz our class using an object named m1 To know. Messaggio
{m1 = new Wheel ("Secret message");
/ / display first before the Rot mesajimizi yazdiriyoruz ...
Console.scriviStringa (m1.toString ());
/ / Sifremizi gonderiyoruz
m1.cifra ("35");
/ / Sifrelenmis mesajimizi yazdiriyoruz
Console.scriviStringa (m1.toString ());
m1.decifra ("35");
/ / ve tekrardan sifremizi gonderip mesajimizi cozuyoruz ..
Console.scriviStringa (m1.toString ());}
}
0 comments:
Post a Comment