Solved

Checksum Function in PL/SQL

Posted on 1998-08-18
8
4,274 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Expert Comment

by:kevincristo
Comment Utility
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
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.

 

Author Comment

by:canlasjp
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now