Obfuscating User input inside a program

4 次查看(过去 30 天)
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 个评论
Greg
Greg 2018-11-30
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...

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2018-11-30
编辑:Adam Danz 2018-11-30
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.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品


版本

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by