Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.
  Public Function EncryptString(theString As String, TheKey As String) As String
    Dim X As Long
    Dim eKey As Byte, eChr As Byte, oChr As Byte, tmp$
        For i = 1 To Len(TheKey)
            'generate a key
            eKey = Asc(Mid$(TheKey, i, 1)) Xor eKey
    Next

    'reset random function
    Rnd -1
    'initilize our key as the random seed
    Randomize eKey
    'generate a pseudo old char
    oChr = Int(Rnd * 256)
    'start encryption
    For X = 1 To Len(theString)
        pp = pp + 1
        If pp > Len(TheKey) Then pp = 1
        eChr = Asc(Mid$(theString, X, 1)) Xor _
                   Int(Rnd * 256) Xor Asc(Mid$(TheKey, pp, 1)) Xor oChr
        tmp$ = tmp$ & Chr(eChr)
        oChr = eChr
    Next
    EncryptString = AsctoHex(tmp$)    

End Function


Public Function DecryptString(theString As String, TheKey As String) As String

Dim X As Long
Dim eKey As Byte, eChr As Byte, oChr As Byte, tmp$
    For i = 1 To Len(TheKey)
        'generate a key
        eKey = Asc(Mid$(TheKey, i, 1)) Xor eKey
Next
'reset random function
Rnd -1
'initilize our key as the random seed
Randomize eKey
'generate a pseudo old char
oChr = Int(Rnd * 256)
'start decryption
tmp$ = HexToAsc(theString)
    DecryptString = ""
    For X = 1 To Len(tmp$)
    pp = pp + 1
    If pp > Len(TheKey) Then pp = 1
    If X > 1 Then oChr = Asc(Mid$(tmp$, X - 1, 1))
    eChr = Asc(Mid$(tmp$, X, 1)) Xor Int(Rnd * 256) Xor _
           Asc(Mid$(TheKey, pp, 1)) Xor oChr
        DecryptString = DecryptString & Chr$(eChr)
Next

End Function


Private Function AsctoHex(ByVal astr As String)

For X = 1 To Len(astr)
hc = Hex$(Asc(Mid$(astr, X, 1)))
nstr = nstr & String(2 - Len(hc), "0") & hc
Next
AsctoHex = nstr

End Function
share|improve this question
    
Where are we supposed to ask questions like this? I'm trying to get similar answers (cstheory.stackexchange.com/questions/11521) but am not sure where to go. –  Noctis Skytower May 24 '12 at 14:58
add comment

closed as too localized by Ninefingers May 24 '12 at 7:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

Yes, it looks quite vulnerable.

It is a variant of a Vigenère cipher, with two changes:

  • The previous ciphertext byte is xor'ed in as well. However, the attacker sees the previous ciphertext byte, and so he can easily undo do that (except for the first byte).

  • A byte from the random number generator is xor'ed in as well. However, the random number generator is seeded with a number from 0-255; an attacker can easily try all 256 possibilities, and see which one works.

So, the obvious way to attack this would be:

  • Xor adjacent ciphertext bytes together (cancelling out the first variant)

  • then iterate through all 256 possible values of eKey, xor out those bytes from the ciphertext (cancelling out the second variant, except we now have 256 possible texts rather than 1).

  • Now, if we guess that the plaintext and the key had (mostly) clear msbits, then we can check which of the 256 possible texts was consistent with that assumption; the completes the cancelling out of the second variant.

  • After that, we've got an ordinary Vigenère ciphertext, we can attack it using any of the standard ways.

share|improve this answer
    
Thank you for answering this! –  Noctis Skytower May 24 '12 at 14:59
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.