import java.security.*;
import java.io.*;
public class SimpleHashExample{
public static void main(String args[]) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
String data = "this is the massage";
byte dataBytes[] = data.getBytes();// Encodes this String into a sequence of bytes
//using the platform's default charset,
//storing the result into a new byte array.
md.update(dataBytes);
byte digest1[] = md.digest();//To find out the digest value.
//The value of the message digest is returned as a byte array
MessageDigest nmd = MessageDigest.getInstance("SHA1");
String ndata = "this is the massage";
byte newdata[] = ndata.getBytes();
nmd.update(newdata);
byte digest2[] = nmd.digest();
//System.out.println("New digest: " + digest2);
System.out.println("Orig. digest: " + Utils.toHex(digest1));
System.out.println("New digest: " + Utils.toHex(digest2));
if(md.isEqual(digest1,digest2)) System.out.println("Digest Verified");
else System.out.println("Digest Verification failed!");
} catch (Exception e) {
System.out.println(e);
}
}
}
// NOT FOR REVIEW
< Proග්රෑming >
Monday, January 24, 2011
Monday, August 23, 2010
C++ oop link list එකක්
/* int link list*/
#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST
class IntNode {
public:
int info;
IntNode *next;
IntNode(int el ,IntNode *ptr = 0){
info = el;
next =ptr;
}
};
class IntSLList{
public:
IntSLList(){
head = tail = 0;
}
~IntSLList();
int isEmpty(){
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead();
int deleteFromTail();
void deleteNode(int);
void display();
bool isInList(int) const;
private:
IntNode *head ,*tail;
};
#endif
//////////////////////////////////////////////////////////////////////////////////////////
/*********intSLList.cpp***********/
#include
#include"intSLList.h"
using namespace std;
IntSLList::~IntSLList(){
for(IntNode *p; !isEmpty();){
p =head->next;
delete head;
head =p;
}
}
void IntSLList::addToHead(int el){
head = new IntNode(el,head);
if(tail==0)
tail= head;
}
void IntSLList::addToTail(int el){
//cout<<"addToTail"<<"\n";
if(tail !=0){
tail->next = new IntNode(el);
tail = tail->next;
}
else
head=tail = new IntNode(el);
}
int IntSLList::deleteFromHead(){
int el = head->info;
IntNode *tmp = head;
if(head==tail)
head=tail=0;
else
head = head->next;
delete tmp;
return el;
}
int IntSLList::deleteFromTail(){
int el =tail->info;
if(head==tail){
delete head;
head=tail=0;
}else{
IntNode *tmp ;
for(tmp=head ; tmp->next != tail ; tmp= tmp->next);
delete tail;
tail =tmp;for(tmp=head ; tmp->next != tail ; tmp= tmp->next)
tail->next= 0;
}
return el;
}
void IntSLList::display(){
IntNode *tmp ;
for(tmp=head ; tmp != 0 ; tmp= tmp->next)
cout<info<<"\n";
}
int main()
{
IntSLList List ;
List.addToTail(82);
List.addToTail(5);
List.addToTail(78);
List.addToTail(78);
List.addToHead(33);
List.addToHead(44);
List.addToHead(53);
List.deleteFromHead();
List.deleteFromTail();
List.display();
return 0;
}
=================
g++ intSLList.cpp
./a.out
=================
OUTPUT
#################
44
33
82
5
78
#################
#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST
class IntNode {
public:
int info;
IntNode *next;
IntNode(int el ,IntNode *ptr = 0){
info = el;
next =ptr;
}
};
class IntSLList{
public:
IntSLList(){
head = tail = 0;
}
~IntSLList();
int isEmpty(){
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead();
int deleteFromTail();
void deleteNode(int);
void display();
bool isInList(int) const;
private:
IntNode *head ,*tail;
};
#endif
//////////////////////////////////////////////////////////////////////////////////////////
/*********intSLList.cpp***********/
#include
#include"intSLList.h"
using namespace std;
IntSLList::~IntSLList(){
for(IntNode *p; !isEmpty();){
p =head->next;
delete head;
head =p;
}
}
void IntSLList::addToHead(int el){
head = new IntNode(el,head);
if(tail==0)
tail= head;
}
void IntSLList::addToTail(int el){
//cout<<"addToTail"<<"\n";
if(tail !=0){
tail->next = new IntNode(el);
tail = tail->next;
}
else
head=tail = new IntNode(el);
}
int IntSLList::deleteFromHead(){
int el = head->info;
IntNode *tmp = head;
if(head==tail)
head=tail=0;
else
head = head->next;
delete tmp;
return el;
}
int IntSLList::deleteFromTail(){
int el =tail->info;
if(head==tail){
delete head;
head=tail=0;
}else{
IntNode *tmp ;
for(tmp=head ; tmp->next != tail ; tmp= tmp->next);
delete tail;
tail =tmp;for(tmp=head ; tmp->next != tail ; tmp= tmp->next)
tail->next= 0;
}
return el;
}
void IntSLList::display(){
IntNode *tmp ;
for(tmp=head ; tmp != 0 ; tmp= tmp->next)
cout<
}
int main()
{
IntSLList List ;
List.addToTail(82);
List.addToTail(5);
List.addToTail(78);
List.addToTail(78);
List.addToHead(33);
List.addToHead(44);
List.addToHead(53);
List.deleteFromHead();
List.deleteFromTail();
List.display();
return 0;
}
=================
g++ intSLList.cpp
./a.out
=================
OUTPUT
#################
44
33
82
5
78
#################
Saturday, June 5, 2010
Fibbonnaci (java) ජාවා වලින්
class Fibbonnaci{
public static void main (String args[]){
System.out.println(fibb(0));
System.out.println(fibb(1));
System.out.println(fibb(2));
System.out.println(fibb(3));
System.out.println(fibb(4));
System.out.println(fibb(5));
System.out.println(fibb(6));
System.out.println(fibb(7));
}
static long fibb(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
else
return fibb(n-1) + fibb(n-2);
}
}
public static void main (String args[]){
System.out.println(fibb(0));
System.out.println(fibb(1));
System.out.println(fibb(2));
System.out.println(fibb(3));
System.out.println(fibb(4));
System.out.println(fibb(5));
System.out.println(fibb(6));
System.out.println(fibb(7));
}
static long fibb(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
else
return fibb(n-1) + fibb(n-2);
}
}
Saturday, May 8, 2010
C වලින් String copy කිරීම
#include<stdio.h>
#include <string.h> /* strcpy() function එක සදහා*/
main(){
char text1[20] = " Mahinda"; /* string buffer */
char text2[20] = " Ranil "; /* string buffer */
printf (" Original string contents are (ඔරිගිනල් text එක) -> %s\n", text1);
/* text2 හි ඇති වචනය text1 ට copy කරන්න.( Copy text2 into text1 ) */
strcpy(text1, text2);
printf (" now string contents are ->%s\n", text1);
/* If text1 is smaller that text2 it will probably overwrite something! */
strcpy(text1, "Fonseka");
printf (" final string contents are: ->%s\n", text1);
}
----------------------------------------------------------------------------------------------------
as@as-desktop:~/Documents/C_CODE$ gcc stringCopy.c
as@as-desktop:~/Documents/C_CODE$ ./a.out
######Out Put (gcc) ########################
Original string contents are (ඔරිගිනල් text එක) -> Mahinda
now string contents are -> Ranil
final string contents are: ->Fonseka
################################
#include
main(){
char text1[20] = " Mahinda"; /* string buffer */
char text2[20] = " Ranil "; /* string buffer */
/* text2 හි ඇති වචනය text1 ට copy කරන්න.( Copy text2 into text1 ) */
strcpy(text1, text2);
printf (" now string contents are ->%s\n", text1);
/* If text1 is smaller that text2 it will probably overwrite something! */
strcpy(text1, "Fonseka");
printf (" final string contents are: ->%s\n", text1);
}
----------------------------------------------------------------------------------------------------
as@as-desktop:~/Documents/C_CODE$ ./a.out
Original string contents are (ඔරිගිනල් text එක) -> Mahinda
now string contents are -> Ranil
final string contents are: ->Fonseka
################################
Subscribe to:
Posts (Atom)