?
Solved

filename encryption

Posted on 2005-03-15
6
Medium Priority
?
408 Views
Last Modified: 2012-05-05
dear all experts,

i want to encrypt a filename to unmeaningful name
e.g. ABCD02082005-0001.txt
becoz it construct from a meaning seq. "ABCD" + MMDDYYYY + "-" + seq. no. + ".txt" i dun want let external know the filename(coz they might try to guess the next filename)
so, do u hv any suggestion for us to do the encryption (i need the easy method, however, diff. to let user know that)

thanks for your suggestion
0
Comment
Question by:kankan
6 Comments
 
LVL 17
ID: 13543260
is YDMYDYMY or some variation too simple?

perhaps

MM (2*(DD) + MM) (YYYY + 100*DD)?

gives 03332155 for today and 03352165 for tomorrow - not easy to see a pattern or will they be trying harder than that?
0
 
LVL 5

Accepted Solution

by:
Rubyn earned 450 total points
ID: 13543554
Option Explicit

'The input should be /-: or numbers only.
Private Function Encrypt(id As String) As String
Dim I As Integer, O As String, Key As Integer
    Let Key = 13 * Rnd
    For I = 1 To Len(id)
        O = O + Chr(Asc(Mid(id, I, 1)) + 20 + Key)
    Next
    Encrypt = O & Chr(Asc("A") + Key)
End Function

Private Function DeEncrypt(E As String) As String
Dim I As Integer, O As String, Key As Integer
    Let Key = Asc(Right(E, 1)) - Asc("A")
    For I = 1 To Len(E) - 1
        O = O + Chr(Asc(Mid(E, I, 1)) - 20 - Key)
    Next
    DeEncrypt = O
End Function

Private Sub Form_Load()
Dim D1 As Date, D2 As Date, Filename As String
D1 = Date
Filename = Encrypt(Date)
D2 = DeEncrypt(CStr(Filename))
MsgBox D1 & vbCrLf & Filename & vbCrLf & D2
End Sub
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 13543954
may be just use double to repreasnt the date

date store in double anyway


ie

Dim a As Date

a = Now
Debug.Print "ABCD" & Replace(CDbl(a), ".", "-") & ".txt"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kankan
ID: 13550671
if i want a different name in each time ?
e.g. my filename -> ABCD02082005-0001.txt
both user c the seee the same file but the filename display in diff. name
user A will see -> VXRT1547RF06D7458.txt
user B will see -> CUJHTG465458JKT511.txt
0
 
LVL 17
ID: 13589516
seems to me that you could multiply different sets of numbers together to reach the same result.
If you translate the actual filename into a number and divide it by several different sets of numbers,
 you could use these numbers to multiply together and recreate the filename. You would probably need to create
your own table of character values so to avoid having illegal filename characters.

Very simple example:
filename=144.txt

1st derived filename=449.txt
2st derived filename=494.txt 'you could change the order as well
3rd derived filename=829.txt
...
863.txt
3344.txt


Just multiply all the values together to get back to the original filename.

You could do the sums in hex to prevent spacing problems.

0
 
LVL 5

Assisted Solution

by:Rubyn
Rubyn earned 450 total points
ID: 13589866
Option Explicit

'The input should be /-: or numbers only.
Private Function Encrypt(id As String, Optional Seed As Integer) As String
Dim I As Integer, O As String, Key As Integer
    'Call Randomize to make the Rnd differ with different seed
    Call Randomize(Seed)
    'Rnd will return value from 0 to 1
    'So Key will vary from 0 to 13
    Let Key = 13 * Rnd
    'Process each character from input string
    For I = 1 To Len(id)
        'Find the ascii code for the current character and add 20(to shift numbers to letter area)
        'Add the key value to avoid easy guessing
        'Convert the code to character and append it to the string
        O = O + Chr(Asc(Mid(id, I, 1)) + 20 + Key)
    Next
    'Return the encryped string and append the key code in letter(ex: key=2 then C)
    Encrypt = O & Chr(Asc("A") + Key)
End Function

Private Function Decrypt(E As String) As String
Dim I As Integer, O As String, Key As Integer
    'Get the key value by getting the code value of the last appended letter
    Let Key = Asc(Right(E, 1)) - Asc("A")
    'Process all character except last one which is key
    For I = 1 To Len(E) - 1
        'Reverse the letter to numbers
        O = O + Chr(Asc(Mid(E, I, 1)) - 20 - Key)
    Next
    'Return the decrypted string
    Decrypt = O
End Function

Private Sub Form_Load()
Dim D As String, D1 As String, D2 As String
Dim Filename1 As String, Filename2 As String
'Source date and number
D = Date & "-0001"
'Encrypt with random seed 1
Filename1 = Encrypt(D, 1)
'Encrypt with random seed 2
Filename2 = Encrypt(D, 2)
'Decrypt Filename1
D1 = Decrypt(Filename1)
'Decrypt Filename2
D2 = Decrypt(Filename2)

MsgBox "Source : " & D & vbCrLf & _
        "File1 : " & Filename1 & vbCrLf & _
        "File2 : " & Filename2 & vbCrLf & _
        "Decrpted File1 : " & D1 & vbCrLf & _
        "Decrpted File2 : " & D2
End Sub
Hope this will be useful :)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

580 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