Program.
NO: 10
IMPLEMENTATION OF MDS
AIM:
To implement the MDS hashing technique.
DESCRIPTION:
MDS proceSses avariable-length message into afixed-length output of 128 bits. The input
Imessage is broken up into chunks of 512-bit blocks. The message is padded so that its length is
divisible by 512. The padding works as follows: first a single bit,1, is appended to the end of the
message. This is followed by as many zeros as are required tob ring the length of the message
up to 64 bits less than a multiple of 512. The remaining bits are
filled up with 64 bits representing
the length of the original message, modulo 2*. The main M DS
algorithm operates on a 128-bit
state. divided into four 32-bit words, denoted A, B, C, and D. These are
initialized to certain fixed
constants. The main algorithm then uses each 512-bit message block in turn to
modify the state
EXAMPLE:
B C D
KË
A C
ALGORITHM:
STEP-1: Read the 128-bit plain text.
STEP-2: Divide into four blocks of 32-bits named as A, B, C and D.
STEP-3: Compute the functions f, g, h and iwith operations such as, rotations,
permutations, etc,.
STEP-4: The output of these functions are combined together as F and performed
circular shifting and then given to key round.
STEP-5: Finally, right shift of 's' times are performed and the results are combined
together to produce the final output.
Program : MDS
import [Link];
import [Link];
public class MDSExample {
public static void main(String[l] args) {
String input = "Hello World";
String mdSHash = calculateMD5(input);
[Link]("MDS hash of" + input + ": " + mdsSHash):
public staticString calculateMDS(String input) {
try
MessageDigest md = [Link]("MDS"):
byte[] messageDigest = [Link]([Link]();
StringBuilder sb = new StringBuilder();
for (byte b: messageDigest){
[Link](String,format("%02x", b):
return [Link]():
catch (NoSuchAlgorithmException c)
[Link] StackTrace();
return null:
Program. NO: 11
IMPLEMENTATION OF SHA-I
AIM:
To implement the SHA-I hashing technique.
DESCRIPTION:
Algorithm 1) is a cryptographic hash function.
In cryptography, SHA-1 (Secure Hash
produces a 160-bit hash value known as message digest. The waythis
SHA-1
it computes a 160-bit condensed output
algorithm works is that fora message of size<264 bits
designed so that it is practicallyinfeasible to
called a message digest. The SHA-1 algorithm is SHA-1
such as
same output message. A hash function
find two input messages that hash to the
as the cryptographic representation of a
used to calculate an alphanumeric string that serves
serve as a digital signature. It is supposed
file or a piece of data. This is called a digest and can
to be unique and non-reversible.
EXAMPLE:
A D
A
ALGORITHM:
256-bit key values.
STEP-1: Read the C, Dand E.
cqual-sized blocks namcd A, B,
five
STEP-2: Divide into the function F.
blocks B, C and D are passcd to
STEP-3: The block E. step-4
The resultant valuc is permuted with and permuted with the resultof
STEP-4: shifted right by 's' times
STEP-5: The block A is key pair and
weight valuc and then with somc other
permutcd with a
STEP-6: Then it is
taken as the first block. times and
block and the block B is shifted by 's'
the second
STEP-7: Block A is taken as
taken as the third block.
the final output.
blocks C and D are taken as the blockD and Efor
STEP-8: The
PROGRAM: (Secure Hash Algorithm)
import [Link].*;public class
SHA1 {
public static void main(String[) a) {try {
MessageDigest md =[Link]("'SHA1");
Algorithm
[Link]("Message igest object info: "); [Link]("
+[Link](0):[Link](" Provider = " +[Link] Provider();
":
[Link](" ToString =" +[Link])); String input =
[Link]([Link]()); bytel] output
= [Link]();[Link]();
[Link]("SHA1(\"M+input+"\") =
+bytesToHex(output));input =
"abc":
[Link]([Link]();output = [Link](); [Link]():
[Link]("SHA1(\"+input+"\") =
+bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";[Link]([Link]();
output = [Link]);
[Link]();
[Link]("SHA1(\" +input+"\") = "+bytesToHex(output);
[Link]("");
catch (Exception e)
[Link]("Exception: " +e);
public static String bytesToHex(bytel] b)
char hexDigit[] ={0', '1', '2, '3, '4', '5', '6,
7, '8, '9, 'A', 'B, 'C, 'D', 'E, 'F};
StringBuffer buf = new StringBuffer();for (int j=0;
j<[Link];j++) {
[Link](hexDigit[(blj] >> 4) & Ox0f]):
[Link](hexDigit[b [i] &0xOf]); } return [Link] (); }
Output:
G C:[Link]
-lelx
Read options and Cilenanes From £ile
C<Eilename>
P:javac [Link]
P:java SHA1
Hessage digeot object info:
Algorithn EHA1
Pyou1der SUN Ves 1on 1.? .nnt Euom SUN, <initialized>
ToString = SHA1 sage
SHA1<" DA39 A3EESE6B4BØD3255BPEF95601890APD8B709
SHA1<"abc"> A9993E36470681.6A BA3E25717850G26C9CDOD89D
SHA1<"abcdefghijklnnopqretuvwxyz")- 32D10C7B8 CF96570CAØ4CE37F2A19D84240D3A89