?
Solved

Checksum Function in PL/SQL

Posted on 1998-08-18
8
Medium Priority
?
4,682 Views
Last Modified: 2008-02-01
Hi!  Does anybody have a checksum function in PL/SQL (or algorithmn) that translates a string of text into a number ?  I prefer to use Oracle's standard function if it is accessible.  I am using this is for authentication purposes.  Thanks.
0
Comment
Question by:canlasjp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:xiaodong
ID: 1081144
I'm not sure about your question.  What does checksum has to do with translating a string to number?  If you just want to transform a string to its corresponding hex values, then you can use the functions available in sql to do that.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1081145
Can you be a bit more specific about what you're looking for, I can give you code to generate a CRC (not Oracle's own method) using the standard CRC algorithm or Fletcher's checksum, but I suspect that isn't what you want.
0
 

Author Comment

by:canlasjp
ID: 1081146
Xiaodong/Answers2000, I am actually looking for a CRC routine or encryption routine written in PL/SQL.   This function should take in a string as input parameter and return a number or encrypted text.  If possible, the function should work on both ASCII and EBCDIC Oracle servers.  Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:kevincristo
ID: 1081147
One other way to acheive this.
I commit the same problem, what I did is, I created a record group in design time and inserted all values with flag at run time, and I handled that values after the successful processing of some function, so as to save sequence index number.
0
 

Author Comment

by:canlasjp
ID: 1081148
Kevin, the solution you proposed will not work for me.  The function (probably server side function) should compute and return the CRC (cyclic redundancy check) number of a given character string.  

Thanks anyway.
0
 
LVL 5

Accepted Solution

by:
Mujeeb082598 earned 300 total points
ID: 1081149
Well this is a start u can use this direct or can modify as u see fit.

-----------------------------------------------------------------------
create or replace function encrypt (strin varchar2)
return number is
  strlen number(5) := nvl(length(strin),0);
  i      number(5) := 1;
  numcnt number    := 0;
  mr     number    := 155;
Begin
  for i in 1..strlen loop
    numcnt := numcnt + (ascii(substr(strin,i,1))+(162 - mr));
    mr := mr-1;
    if mr = 115 then
      mr := 155;
    end if;
  end loop;
  Return numcnt;
End;

---------------------------------------------------------------------

Output:

Select encrypt('Mujeeb-ur-Rehman') from dual;

ENCRYPT('MUJEEB-UR-REHMAN')
---------------------------
                       1756

Now u can use this number to verify what ever u want to verify.

Hope this help's.
0
 

Author Comment

by:canlasjp
ID: 1081150
Thanks Mujeeb.  This is ok but I still need to test this in an EBCDIC machine.  Can you just explain what the MR variable and its values are for ?
0
 
LVL 5

Expert Comment

by:Mujeeb082598
ID: 1081151
You are most welcome.

The MR variable is used to add extra calcutaion in the string so that one can not guess in an easy way by just adding the values one after another.

U can say it is just added salt to through someone out of the track who want to reproduce the calculated number by adding the values.

By the way MR stands for my name initials :) and the starting value if u notice is 155 which is 'r' and when it reaches 115 which again is 'M' it reset it to 155 again :) and it continues this way till whole string is calculated.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question