Use for-loop on characters in a textfile
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Josh Samnja
el 18 de Sept. de 2018
Respondida: Walter Roberson
el 18 de Sept. de 2018
I have a plain text file that is going to be encrypted - where I'll use double as part of the process. I read the text file
text = fileread('textfile.txt')
Then I need to get the letters into numbers
lettertoNumber = double(text)
Now comes the part I'm struggling with. I need to have a for-loop that goes through lettertoNumber, which also needs to take lower/captial letters into consideration.
for ii = 1:length(lettertoNumber)
?? = ???????
?? = ???????
end
Greatly appreciate any input.
3 comentarios
Walter Roberson
el 18 de Sept. de 2018
double(text) would apply double() to the entire vector of characters individually.
Respuesta aceptada
Walter Roberson
el 18 de Sept. de 2018
Use lookup tables. Like
MAP_INVALIDS_TO = -1;
mapping = zeros(1,255) + MAP_INVALIDS_TO;
mapping('a':'z') = 1:26;
mapping('A':'Z') = 1:26;
mapped = mapping(text); %valid to use characters as indices
mapped(mapped == MAP_INVALIDS_TO) = []; %delete characters that had no mapping
Modified versions of this can be used for situations such as encoding the other characters as pairs of values, or for using "shift-in" / "shift-out" to switch between encodings.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Encryption / Cryptography en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!