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 6956775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:54:49+00:00 2026-05-27T14:54:49+00:00

Could anyone suggest please how I can achieve a substitution cipher style; encrypt and

  • 0

Could anyone suggest please how I can achieve a substitution cipher style; encrypt and decrypt function in VBA. I appreciate hashing is considered the better way but I need reversible encryption. Many Thanks.

  • 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-05-27T14:54:50+00:00Added an answer on May 27, 2026 at 2:54 pm

    Many thanks for all the answers provided in reference to my question, it’s good to see there are different approaches, this is one I coded yesterday morning. It allows a different cipher keyword/phrase to be used for both Upper & Lowercase letters, I have used ‘Zebras’ in this example, it also runs a second pass with the ROT13 cipher. Encryption method:

    Public Function Encrypt(strvalue As String) As String
    
    Const LowerAlpha    As String = "abcdefghijklmnopqrstuvwxyz"
    Const LowerSub      As String = "zebrascdfghijklmnopqtuvwxy" 'zebras
    Const UpperAlpha    As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Const UpperSub      As String = "ZEBRASCDFGHIJKLMNOPQTUVWXY" 'ZEBRAS
    
    Dim lngi            As Long
    Dim lngE            As Long
    Dim strEncrypt      As String
    Dim strLetter       As String
    
    If strvalue & "" = "" Then Exit Function
    
    For lngi = 1 To Len(strvalue)
    
        strLetter = Mid(strvalue, lngi, 1)
    
        Select Case Asc(strLetter)
    
            Case 65 To 90 'Uppercase
                'Find position in alpha string
                For lngE = 1 To Len(UpperAlpha)
                    If Mid(UpperAlpha, lngE, 1) = strLetter Then GoTo USub
                Next
    USub:
                strEncrypt = strEncrypt & Mid(UpperSub, lngE, 1)
    
            Case 97 To 122 'Lowercase
                'Find position in alpha string
                For lngE = 1 To Len(LowerAlpha)
                    If Mid(LowerAlpha, lngE, 1) = strLetter Then GoTo LSub
                Next
    LSub:
                strEncrypt = strEncrypt & Mid(LowerSub, lngE, 1)
    
            Case Else 'Do not substitute
    
                strEncrypt = strEncrypt & strLetter
    
        End Select
    
    Next
    
    'Now pass this string through ROT13 for another tier of security
    
    For lngi = 1 To Len(strEncrypt)
        Encrypt = Encrypt & Chr(Asc(Mid(strEncrypt, lngi, 1)) + 13)
    Next
    
    End Function
    

    And this is the Decryption that goes with it:

    Public Function Decrypt(strvalue As String) As String
    
    Const LowerAlpha    As String = "abcdefghijklmnopqrstuvwxyz"
    Const LowerSub      As String = "zebrascdfghijklmnopqtuvwxy" 'zebras
    Const UpperAlpha    As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Const UpperSub      As String = "ZEBRASCDFGHIJKLMNOPQTUVWXY" 'ZEBRAS
    
    Dim lngi            As Long
    Dim lngE            As Long
    Dim strDecrypt      As String
    Dim strLetter       As String
    
    If strvalue & "" = "" Then Exit Function
    
    'Reverse the ROT13 cipher
    
    For lngi = 1 To Len(strvalue)
        strDecrypt = strDecrypt & Chr(Asc(Mid(strvalue, lngi, 1)) - 13)
    Next
    
    'Now reverse the encryption
    
    For lngi = 1 To Len(strDecrypt)
    
        strLetter = Mid(strDecrypt, lngi, 1)
    
        Select Case Asc(strLetter)
    
            Case 65 To 90 'Uppercase
                'Find position in sub string
                For lngE = 1 To Len(UpperSub)
                    If Mid(UpperSub, lngE, 1) = strLetter Then GoTo USub
                Next
    USub:
                Decrypt = Decrypt & Mid(UpperAlpha, lngE, 1)
    
            Case 97 To 122 'Lowercase
                'Find position in sub string
                For lngE = 1 To Len(LowerSub)
                    If Mid(LowerSub, lngE, 1) = strLetter Then GoTo LSub
                Next
    LSub:
                Decrypt = Decrypt & Mid(LowerAlpha, lngE, 1)
    
            Case Else 'Do not substitute
    
                Decrypt = Decrypt & strLetter
    
        End Select
    
    Next
    
    End Function
    

    I hope the coding is very simple to follow for those who do not have vast experience with VBA coding and it can be lifted straight from the page; but again thanks for all the other answers.

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

Sidebar

Related Questions

Could anyone please suggest a proper format of comments I should use in a
Can anyone suggest how I could do this: Using an image variable I want
Could anyone please suggest a software process suitable to the work our team? We
Could anyone suggest a good packet sniffer class for c++? Looking for a easy
Could anyone suggest books or materials to learn unit test? Some people consider codes
I wonder if anyone could suggest the best way of looping through all the
just wondering if anyone could suggest why I might be getting an error? I'm
Could anyone explain me why: function doAjax() { var xmlHttpReq = false; try {
Could anyone can tell me where I can find full ASP.NET MVC beta documentation?
Can anyone suggest how to debug stored procedure from a remote sql server using

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.