error on decrypting a phrase

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 :)
 

agraham

Expert
Licensed User
Longtime 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 :)
 

Raytracer

Member
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 :)

tried...
in this way:
B4X:
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:
B4X:
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... :(
 

agraham

Expert
Licensed User
Longtime 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.

B4X:
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()))
 

JJM

Active Member
Licensed User
Longtime 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
 

Attachments

  • CryptoBDD1.sbp
    2.1 KB · Views: 278

agraham

Expert
Licensed User
Longtime User
B4X:
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.

B4X:
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
 

JJM

Active Member
Licensed User
Longtime User
Crypto

Hello Agraham,

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

Best regards

JJ M
 
Top