Solved

Equivalent functions in sql server 2000 against functions of powerbuilder 7.

Posted on 2004-08-11
5
633 Views
Last Modified: 2008-02-01

SELECT USER_ID,PASSWORD FROM PASSWORD

USER_ID PASSWORD
A      “›‹‡
B      ³¹‡
C      §‹µ¹•¥
D      ¯‹‘…§

The values in the column password has been saved from within a front end by a function f_encrypt.

Here
“›‹‡   means DIBA      (created from f_encrypt('DIBA'))
³¹‡   means BUYA
§‹µ¹•¥ means NAWZIR
¯‹‘…§ means RADFAS

Please note that “›‹‡ is created from f_encrypt('DIBA').Similarly DIBA can be obtained by f_decrypt('“›‹‡')

The two functions are:
[function f_encrypt]
integer chrvalue, seed,mlen,i
string  mstring, mchar
chrvalue = 0
seed = 17
mchar = ''
mstring  = trim(given_string)  
mlen     = len(mstring)
FOR  I = 1 TO mlen
     chrvalue = asc(mid(mstring,I,1))
     chrvalue = ((chrvalue + seed + 95 - I)*2) - 211
     mchar = mchar + char(chrvalue)
next
return (mchar)

[function f_decrypt]
integer chrvalue,i,mlen, seed
string mstring, mchar

chrvalue = 0
seed = 17
mchar = ''
mstring = trim(given_string)  
mlen    = len(mstring)

for  I = 1 TO mlen
       chrvalue = ASC(mid(mstring,I,1))
       chrvalue = (chrvalue + 211)/2 +I -  95 - SEED
       mchar    = mchar + char(chrvalue)
next

return (mchar)

I want those two functions/procedure to be created in sql server 2000.
0
Comment
Question by:Mateen
[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
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
patrikt earned 500 total points
ID: 11781081
First one:

CREATE FUNCTION f_encrypt (@given_string varchar(50))
RETURNS varchar(50)
AS
BEGIN
declare @chrvalue int, @seed int, @mlen int,@i int
declare @mstring varchar(50), @mchar varchar(50)

SELECT @chrvalue = 0,@seed = 17,@mchar = ''
SET @mstring  = ltrim(rtrim(@given_string))  
SET @mlen     = len(@mstring)
SET @i=1
WHILE @i<=@mlen
BEGIN
     SET @chrvalue = ascii(substring(@mstring,@I,1))
     SET @chrvalue = ((@chrvalue + @seed + 95 - @I)*2) - 211
     SET @mchar = @mchar + char(@chrvalue)
     set @I=@I+1
END
return (@Mchar)
END
0
 
LVL 12

Expert Comment

by:patrikt
ID: 11781104
Secon one:
CREATE functION f_decrypt (@given_string varchar(50))
RETURNS varchar(50)
AS
BEGIN
declare @chrvalue int,@i int,@mlen int, @seed int
declare @mstring varchar(50), @mchar varchar(50)

SELECT @chrvalue = 0,@seed = 17,@mchar = ''
SET @mstring = ltrim(rtrim(@given_string))  
SET @mlen    = len(@mstring)
SET @i=1

WHILE @I <= @mlen
BEGIN
       SET @chrvalue = ASCii(substring(@mstring,@I,1))
       SET @chrvalue = (@chrvalue + 211)/2 +@I -  95 - @SEED
       SET @mchar    = @mchar + char(@chrvalue)
      SET @i=@i+1
END

return (@mchar)
END
0
 
LVL 12

Expert Comment

by:patrikt
ID: 11781116
I only rewrited sintax to SQL. You have to check data types if it is usable for your scenario.

SQL hates loops so I would try to find beter performing aproach...But for short strings it is not significant.

Patrik
0
 

Author Comment

by:Mateen
ID: 11781254
Many many thanks patrikt
0
 

Author Comment

by:Mateen
ID: 11781272
Please do submit when u find better approach. I shall be delighted.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

752 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