encrypt a text string without weird chars

HarryCallaghan

Board Regular
Joined
Jan 30, 2013
Messages
50
Hello.

I have a table with codes of articles and prices and i need to give the table to some person but he can't know what are the real codes of the articles. For example, if i have an article with the code "R76543H65" i want to "encrypt" to something like "T67R78598" or something like that. I've tried some XOR encrypt functions but what it does is to encrypt with weird chars and i dont want the person who i have to give the table to know that the codes arent real, i dont know if i'm explaining that well. I have like 14K articles.

That's the XOR function i have tried:

Code:
Function XorC(ByVal sData As String, ByVal sKey As String) As String
    Dim l As Long, i As Long, byIn() As Byte, byOut() As Byte, byKey() As Byte
    Dim bEncOrDec As Boolean
     'confirm valid string and key input:
    If Len(sData) = 0 Or Len(sKey) = 0 Then XorC = "Invalid argument(s) used": Exit Function
     'check whether running encryption or decryption (flagged by presence of "xxx" at start of sData):
    If Left$(sData, 3) = "xxx" Then
        bEncOrDec = False 'decryption
        sData = Mid$(sData, 4)
    Else
        bEncOrDec = True 'encryption
    End If
     'assign strings to byte arrays (unicode)
    byIn = sData
    byOut = sData
    byKey = sKey
    l = LBound(byKey)
    For i = LBound(byIn) To UBound(byIn) - 1 Step 2
        byOut(i) = ((byIn(i) + Not bEncOrDec) Xor byKey(l)) - bEncOrDec 'avoid Chr$(0) by using bEncOrDec flag
        l = l + 2
        If l > UBound(byKey) Then l = LBound(byKey) 'ensure stay within bounds of Key
    Next i
    XorC = byOut
    If bEncOrDec Then XorC = "xxx" & XorC 'add "xxx" onto encrypted text
End Function
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Do you actually need to encrypt the codes or could you just create a sequential list of dummy codes? Presumably you'd need to store a lookup table somewhere of what these dummy codes related to.
 
Upvote 0
It's kind of a sequential dummy list yes. I don't mind if i have to store the original table with codes and dummy codes.
 
Upvote 0
Are you comfortable enough to generate that on your own? Literally it would just mean extracting all the genuine codes you have and then creating a list of sequential numbers to be used in their place:


Excel 2010
AB
1Real CodeDummy Code
2R76543H65CODE0000001
3R71123I12CODE0000002
4S999999P00CODE0000003
5 and so on.
Sheet2
Cell Formulas
RangeFormula
B2="CODE"&TEXT(ROWS($B$2:B2),"0000000")


If you keep the reference table (as above) you will always be able to match back between the dummies supplied and what the real codes are.
 
Upvote 0

Forum statistics

Threads
1,216,049
Messages
6,128,496
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top