Obfuscating User input inside a program

조회 수: 8 (최근 30일)
Casey123
Casey123 2018년 11월 29일
편집: Adam Danz 2018년 11월 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