|
Главная | Правила | Регистрация | Дневники | Справка | Пользователи | Календарь | Поиск | Сообщения за день | Все разделы прочитаны |
|
Опции темы | Опции просмотра |
11.12.2014, 16:00 | #1 (permalink) |
Member
Регистрация: 13.04.2013
Сообщений: 12
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
Нужна помощь в Matlab
s = '/ b_t3{$ H~MO 6JTQI> Зашифруйте текст , содержащийся в файле gettysburg .txt , и текст самой функции encrypt.m. Функция encrypt: function encrypt(filein,fileout) %ENCRYPT Apply the CRYPTO function to a text file. % ENCRYPT % with no arguments prompts for a input file name. % ENCRYPT inputfilename % encrypts the text in the input file and displays the results. % ENCRYPT inputfilename outputfilename % stores the encrypted text in the output file. % See also CRYPTO. % Copyright 2012 Cleve Moler and The MathWorks, Inc. if nargin < 1 filein = input('Input file = ','s'); end fin = fopen(filein); if nargin == 2 fout = fopen(fileout,'w'); else fout = 1; end while ~feof(fin) s = fgetl(fin); t = crypto(s); fprintf(fout,'%s\n',t); end fclose all; Функция crypto: function y = crypto(x) % CRYPTO Cryptography example. % y = crypto(x) converts an ASCII text string into another, coded string. % The function is its own inverse, so crypto(crypto(x)) gives x back. % See also: ENCRYPT. % Copyright 2012 Cleve Moler and The MathWorks, Inc. % Use a two-character Hill cipher with arithmetic modulo 97, a prime. p = 97; % Choose two characters above ASCII 128 to expand set from 95 to 97. c1 = char(169); c2 = char(174); x(x==c1) = 127; x(x==c2) = 128; % Convert to integers mod p. x = mod(real(x-32),p); % Reshape into a matrix with 2 rows and floor(length(x)/2) columns. n = 2*floor(length(x)/2); X = reshape(x(1:n),2,n/2); % Encode with matrix multiplication modulo p. A = [71 2; 2 26]; Y = mod(A*X,p); % Reshape into a single row. y = reshape(Y,1,n); % If length(x) is odd, encode the last character. if length(x) > n y(n+1) = mod((p-1)*x(n+1),p); end % Convert to ASCII characters. y = char(y+32); y(y==127) = c1; y(y==128) = c2; |
11.12.2014, 16:00 | |
Helpmaster
Member
Регистрация: 08.03.2016
Сообщений: 0
|
Информативные ответы вы можете найти в схожих обсуждениях Помогите с задачей в MATLAB Нужна помощь по МК Помогите пожалуйста MATLAB |
Ads | |
Member
Регистрация: 31.10.2006
Сообщений: 40200
Записей в дневнике: 0
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 55070
|
Опции темы | |
Опции просмотра | |
|
|