Results 1 to 5 of 5

Thread: [RESOLVED] Swap letters - sort of like a simple encryption

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Swap letters - sort of like a simple encryption

    I was helping someone who wanted to replace capital letters in a string with their "opposites", eg Z to A, Y to B, X to C, etc. I came up with a way to do it by determining the Ascii value of the letters and using that value minus 64 as an index to get it's opposite via a hard-coded "ZYXW..." string. That works but I first tried to come up with a formula for converting the Ascii values of the letters (65 to 90) to their opposite, eg 90 to 65, 89 to 66, etc. but I was unsuccessful. Can anyone think of an algorithm for that that works?

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Swap letters - sort of like a simple encryption

    155 - 90 = 65
    155 - 89 = 66
    155 - 88 = 67
    ....
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

  4. #4
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: [RESOLVED] Swap letters - sort of like a simple encryption

    Also, in general your function is linear, since going up some amount in the input causes some constant change in the output--go up 5 numbers in the input, go down 5 in the output. The relation must then be, for instance,

    O = m*I + b,

    for constants m and b. You can find them with some sample data. (I only mention this because it's a more general method to solve similar problems that occur pretty frequently. Otherwise, you're left with "intuit"ing the answer.)
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] Swap letters - sort of like a simple encryption

    Close but no cigar
    Code:
            Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            Dim es As String
            Dim c As Char
            Dim i As Integer
            For Each c In s
                i = Asc(c) Xor 27
                Debug.WriteLine(Chr(i))
            Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width