how to xor a single value with in a loop with an input value and it may be in single value i.e it cannot be overwritten by next iteration values all iteration results must be shown at output?

6 visualizaciones (últimos 30 días)
hello i have a problem in solving stream cipher encryption my problem is how to xor a single value with in a loop with an input value and it may be in single value i.e it cannot be overwritten by next iteration values all iteration results must be shown at output? can anyone can help me........... my peice of code is >>clc
>>clear all
%% plain text
p=input('enter the data as decimal value','s')
d=length(p)
%% STEP 1: INITIALIZING S ANT T VECTORS
% intializing key
key = input('Enter the cipher key: ','s' );
x=256-length(key);
% repeating key
k=repmat(key,1,x);
% equalizing columns of plain-text and repeated key
y=length(k);
q=257:y;
% replacing unwanted colums by empty slots
k(:,q) = [];
% deleting unwanted columns in k i.e key matrix
ONE = int32(1);
colsleft = setdiff(ONE:size(k,2),q);
k = k(1,colsleft);
t=k;
% initilazing s vector
s=[0:255];
%% STEP 2: INITIAL PERMUTATION
j=0;
for i=0:255
f=j+s(i+1)+t(i+1);
j=mod(f,256);
%swapping values
temp=s(i+1);
s(i+1)=s(j+1);
s(j+1)=temp;
end
%% STEP 3: STREAM GENERATION
i=0;
j=0;
for e=1:d
i=mod(i+1,256);
j=mod((j+s(i+1)),256);
% swapping values
w=s(i+1);
s(i+1)=s(j+1);
s(j+1)=w;
h=mod((s(i+1)+s(j+1)),256);
% ONE BIT KEY VALUE
k=s(h)
%% here i want to xor single bit of k with single value of input and it cannot be overwritten by loops other value help me
c(e)=xor(k(1,e),p(e))
end

Respuestas (0)

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by