Obfuscating User input inside a program
4 views (last 30 days)
Show older comments
Hello, I am Trying to Obfuscate code inside a Matlab program, I am not trying to Obfuscate the program, I want it to do it inside the program.I don't want to use the P-code function.
The First part of the program askes for user input, however the thing that I want my program to do is Obfuscate the user input into undecipherable text, then I want the program to decipher it back into what the user had orginally typed. I am not trying to package the program at all!
This is what I have so far:
prompt = 'Type what you want to obfuscate: :;
Code = input(prompt, 's');
I was wanting to know what I would do and if it was possible.
1 Comment
Greg
on 30 Nov 2018
Your second question is easy: of course it is possible.
The first question is almost unanswerable. The term "obfuscation" by itself doesn't carry a definition of implementation. You could simply move each character down the alphabet one character (ABC becomes BCD) and call it obfuscated. Or you could spend a billion dollars and man-decades of effort inventing an NSA level encryption algorithm. Or anything in between...
Answers (1)
Adam Danz
on 30 Nov 2018
Edited: Adam Danz
on 30 Nov 2018
As Greg mentioned, 'obfuscation' isn't descriptive enough but here's an example that can get you started. The user will enter a character array which is converted to a vector of integers. You can then do simple math on the vector to encode it, but be sure the vector remains integers. To decode it, you just do the inverse math. Here's an example that involves a random integer so that identical inputs are encoded differently each time.
UserInput = input('Type what you want to obfuscate: ', 's'); %my example: Yipppy! Today is 11/30
% define encode and decode functions
r = randi(20, 1,1); % draw a random int
encode = @(c) char(fliplr(c+r));
decode = @(n) char(fliplr(n-r));
% To encode the user input
encrypted = encode(UserInput)
encrypted =
'9<8::)|r)jmx])*yyyrb' %depends on the random variable
% To decode the encryption
decrypted = decode(encrypted)
decrypted =
'Yipppy! Today is 11/30'
If the decoding function belongs to a separate workspace you'll need to replace the random integer with a hard-coded integer. If the function stops running between the encode and decode phase, you'll need to make the anonymous functions persistent variables.
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!