error on decrypting a phrase

Discussion in 'Questions (Windows Mobile)' started by Raytracer, Aug 21, 2008.

  1. Raytracer

    Raytracer Member Licensed User

    secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
    secret() = strsplit(secodes,"-")
    For i = 0 to arraylen(secret())-1
    secret(i)=bit.HexToDec(secret(i))
    Next
    strings() = crypto.Decrypt(passphrase2,secret())
    stringa = Bit.bytestostring(strings(),0,arraylen(strings()))

    this is my sub, smply. This are the steps.
    1- give a phrase
    2- convert the string in an array of bytes
    3- crypt it with a passphrase
    4- change the bytes value from dec to hex and separate them with "-"
    done.
    now with the sub wrote here i'm trying to do the inverse (ie to have the prhase back from the secodes string) but i get an error...
    anyone know why?
    thank you all :)
     
  2. agraham

    agraham Expert Licensed User

    It's the same problem you had before when I told you "By reassigning the secret array with the return of StrSplit you are changing it from an array of Bytes to an array of Strings which is what StrSplit returns". In this case "secret(i)=bit.HexToDec(secret(i))" is setting secret(i) to a string that represents a decimal number and not a byte! You would really be better of using my BytesConverter library :)
     
  3. Raytracer

    Raytracer Member Licensed User

    tried...
    in this way:
    Code:
    secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
    secret() = strsplit(secodes,
    "-")
    bconv.New1
    for i = 0 to arraylen(secret())-1
    secret(i)=
    bit.HexToDec(secret(i))
    next
    strbyte()=bconv.Int32ToBytes(secret())
    strings() = crypto.Decrypt(passphrase2,strbyte())
    stringa = 
    Bit.bytestostring(strings(),0,arraylen(strings()))
    says crypto error.
    and in this way:
    Code:
    secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
    secret() = strsplit(secodes,
    "-")
    bconv.New1
    strbyte()=bconv.HexToBytes(secret())
    strings() = crypto.Decrypt(passphrase2,strbyte())
    stringa = 
    Bit.bytestostring(strings(),0,arraylen(strings()))
    says crypto error again... :(
     
  4. agraham

    agraham Expert Licensed User

    You are using it wrong. You don't need StrSplit(). HexToBytes(HexString) returns a byte array from a Hex string. HexFromBytes does the opposite.

    Code:
    secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
    bconv.New1
    strbyte()=bconv.HexToBytes(secodes())
    strings() = crypto.Decrypt(passphrase2,strbyte())
    stringa = 
    Bit.bytestostring(strings(),0,arraylen(strings()))
     
  5. JJM

    JJM Active Member Licensed User

    Crypoto

    Hello,

    I have writen that lines like you said to Raytracer and sometimes I get an error!
    Why?

    My best regards

    JJ M
     

    Attached Files:

  6. agraham

    agraham Expert Licensed User

    Code:
    lign="364f[COLOR="Red"][B][SIZE="4"]0[/SIZE][/B][/COLOR]215f7708663" '  created by btnEncrypt_Click (Luck)- error
    You are missing a character in this line because Bitwise.DecToHex doesn't always return two characters.

    Code:
    For i = 0 To ArrayLen(secret())-1 'Show the encrypted data in the TextBox
       If secret(i) < 16 Then
          s = s & 
    "0"
       
    End If
       s = s & BitW.DecToHex(secret(i)) & 
    " "
    Next
     
  7. JJM

    JJM Active Member Licensed User

    Crypto

    Hello Agraham,

    Thank you very much.
    It's run fine now.

    Best regards

    JJ M
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice