?
Solved

filename encryption

Posted on 2005-03-15
6
Medium Priority
?
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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