[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4861
  • Last Modified:

Checksum Function in PL/SQL

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
canlasjp
Asked:
canlasjp
1 Solution
 
xiaodongCommented:
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
 
Answers2000Commented:
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
 
canlasjpAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kevincristoCommented:
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
 
canlasjpAuthor Commented:
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
 
Mujeeb082598Commented:
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
 
canlasjpAuthor Commented:
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
 
Mujeeb082598Commented:
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now