Solved

Checksum Function in PL/SQL

Posted on 1998-08-18
8
4,360 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 100 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

809 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