Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:06:57+00:00 2026-06-15T18:06:57+00:00

I have two functions. An encryption function and a decryption function (see below). The

  • 0

I have two functions. An encryption function and a decryption function (see below). The decryption function doesn’t work 100% of the time with specific words and I cannot figure out the reason why. Can someone help me figure this out? I am testing this two functions using the following select statements after the functions are in place.

select [dbo].[ufn_EncryptString]('Test1') --This string works
select [dbo].[ufn_DecryptString]('Ôæõ÷µ') 

select [dbo].[ufn_EncryptString]('diaz-mayo') --This string doesn't work 
select [dbo].[ufn_DecryptString]('äêãý±òçĀ÷')

You would think it has something to do with “-” but there are instances when is just a plain name with no spaces or special character and the string cannot be decrypted.

See functions below:

 CREATE FUNCTION [dbo].[ufn_EncryptString] ( @pClearString VARCHAR(100) )
    RETURNS NVARCHAR(100) AS
    BEGIN

    DECLARE @vEncryptedString NVARCHAR(100)
    DECLARE @vIdx INT
    DECLARE
 @vBaseIncrement INT

    SET @vIdx = 1
    SET @vBaseIncrement = 128
    SET @vEncryptedString = ''

    WHILE @vIdx <= LEN(@pClearString)
    BEGIN
        SET @vEncryptedString = @vEncryptedString + 
                                NCHAR(ASCII(SUBSTRING(@pClearString, @vIdx, 1)) +

      @vBaseIncrement + @vIdx - 1)
        SET @vIdx = @vIdx + 1
    END

    RETURN @vEncryptedString

END
GO


CREATE FUNCTION [dbo].[ufn_DecryptString] ( @pEncryptedString NVARCHAR(100) )
RETURNS VARCHAR(100) AS
BEGIN

DECLARE @vClearString VARCHAR(100)
DECLARE @vIdx INT
DECLARE @vBaseIncrement INT

SET @vIdx = 1
SET @vBaseIncrement = 128
SET @vClearString = ''

WHILE @vIdx <= LEN(@pEncryptedString)
BEGIN
    SET @vClearString = @vClearString + 

            CHAR(UNICODE(SUBSTRING(@pEncryptedString, @vIdx, 1)) - 

        @vBaseIncrement - @vIdx + 1)
    SET @vIdx = @vIdx + 1
END

RETURN @vClearString

END
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:06:59+00:00Added an answer on June 15, 2026 at 6:06 pm

    I think your function works fine, your example is the issue.

    select [dbo].[ufn_DecryptString]('äêãý±òçĀ÷')
    

    Doesn’t work… however the following works just fine:

    select [dbo].[ufn_DecryptString](N'äêãý±òçĀ÷')
    

    Notice the leading N on the string literal? Since your input parameter is actually a UNICODE string, you need to prefix the literal with N in order to prevent it from being cast to a ASCII string…

    From MSDN:

    Unicode constants are specified with a leading N: N’A Unicode string’.

    Otherwise, when it is converted to ASCII, you’re actually passing in äêãý±òçA÷… only the Ā character isn’t represented in the CHAR literal, which is why your issue was intermittent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions, one function calling the other. Below is a simple analogy
I have two functions that return simple strings. Both are registered. $.views.helpers({ parseDate: function
I have two functions here function Preloader() {} Preloader.prototype = { init:function() { //
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I have two functions hooked on the submit event of a form. Each function
i have two functions, the parent function is __triggerAction, than child function is __triggerNormal
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I have two functions in my js file: function all_opened() { allToggle(true); } function
I have two functions: f(n) = 2; g(n) = 10 ^ 100; I have
I have a program that XORs two files together using one time pad encryption.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.