# Android QuestionNeed simple encryption with standard alpha numeric output

#### tsteward

##### Well-Known Member
Longtime User
I need a routine to do a really simple encryption that will work for B4A and B4J.
Output needs to be standard aplha numeric characters
Data to be encrypted will only be up to 10 alpha numeric characters

I could do simple character substitution but that may be a little too simple.
Result needs to be something I can hand write on the back of a business card and decrypt later on.

Thoughts?

#### wonder

##### Expert
Longtime User
Here's an idea:

Establish a small secret value X (for example: X = 5).
Establish a rule for every character of your string.
Assign the characters numeric values (for example ASCII code).

B4X:
``````X = 5
Position:     [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ]
Rule:          +2x   +x    -x    -2x   +2x   -x    -x    +2x   -2x   +x``````

Example for the string: thisiscool

B4X:
``````Position:     [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ]

-------------------------------------------------------------------------
Char:      [ t ] [ h ] [ i ] [ s ] [ i ] [ s ] [ c ] [ o ] [ o ] [ l ]
ASCII:               
-------------------------------------------------------------------------

pos(0) = 116 + 2x = 126
pos(1) = 104 +  x = 109
pos(2) = 105 -  x = 100
pos(3) = 115 - 2x = 105
pos(4) = 105 + 2x = 115
pos(5) = 115 -  x = 110
pos(6) = 099 -  x =  94
pos(7) = 111 + 2x = 121
pos(8) = 111 - 2x = 101
pos(9) = 108 +  x = 113``````

Recoded back to ASCII: ~mdisn^yeq

You may now handwrite this new string in the back of your business card.
To decrypt you'll need to reverse the process and perform the inverse rules for every position.

https://www.branah.com/ascii-converter

EDIT:
Using this example as a starting point, the possibilities are endless. You can have 7 different sets of rules, one for each day of the week and your value X can represent the day of the month. The same initial string would always be different if not encoded on the same day.

Use your imagination. Last edited:

#### mangojack

##### Well-Known Member
Longtime User
I think that should be ..
B4X:
``````pos(0) = 116 + (2*x) = 126
pos(1) = 104 + x = 109
pos(2) = 105 - x = 100
pos(3) = 115 - (2*x) = 105
pos(4) = 105 + (2*x) = 115
pos(5) = 115 - x = 110
pos(6) = 099 - x = 94
pos(7) = 111 + (2*x) = 121
pos(8) = 111 - (2*x) = 101
pos(9) = 108 + x = 113``````

#### wonder

##### Expert
Longtime User
Mangojack, my post was in pseudocode... #### mangojack

##### Well-Known Member
Longtime User
I was aware that you were aware .. • wonder

#### Erel

##### B4X founder
Staff member
Longtime User
You can use RandomAccessFile.WriteEncryptedObject to write the data to a file. Read the data and convert it to base64.

Replies
0
Views
327
Replies
4
Views
7K
Replies
2
Views
566
Replies
82
Views
40K
Replies
1
Views
856