Doing a simple crypter without use library

KashMalaga

Member
Licensed User
Longtime User
Im trying to do a simple crypter string with a single key and base64encode.
Works fine under another language but i have some troubles to port it to b4a.

JvIye.png


Problem comes using str option, i must to use a string2 instead to can get substr?

Until now its imposible to do it
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Log (Encrypt("sdfsdfsdfsdf"))
End Sub

Sub Encrypt(str As String) As String
   Dim su As StringUtils
   Dim result As StringBuilder
   result.Initialize
   Dim key, c, keyChar As String
   key = "a      "
   For i = 0 To str.Length - 1
      c = str.CharAt(i)
      Dim start As Int
      start = (key.Length + (i Mod key.Length) - 1) Mod key.Length
      keyChar = key.CharAt(start)
      c = Chr(Asc(c) + Asc(keychar))
      result.Append(c)
   Next
   Return su.EncodeUrl(su.EncodeBase64(result.ToString.GetBytes("UTF8")), "UTF8")
End Sub
 
Upvote 0

KashMalaga

Member
Licensed User
Longtime User
Thanks for your answer Erel and your time.

Looks fine. But i have the same problem than before.

Using your string and key to crypt, results are totaly different.

wpPDhcKGwpPChMKGwpPChMOHwpPChMKG > b4a
k8WGk4SGk4THk4SG > php

thanks for the uses of stringutils!
 
Last edited:
Upvote 0

KashMalaga

Member
Licensed User
Longtime User
I know that erel is so busy and its really hard to answer all question.

Somebody can check where is the fail.

I check everything and looks fine :(
 
Upvote 0
Top