Assign index value to bits in cyclic order

2 次查看(过去 30 天)
Hi,
I am working on implementing following logic in matlab
I calculating index variable value based on length of my ciphertext
Index Variable P=Mod(l,3) where l is length of ciphertext after converting it into binary
Say ciphertext is 11001011 01111010 10101010 10011001 01010101
This data is five bytes. So l=5 therefore p=2 ((Mod(l,3)) &
then I want to assign index variable to the bits of cipher text in cylic order based on calculated value of index variable
P=0 then
P=1 then
P=2 then after this again p=0
Operation IndexVariable,P
(11) 2
(00) 0
(10) 1
(11) 2
(01) 0
(11) 1
(10) 2
(10) 0
(10) 1
(10) 2
(10) 0
(10) 1
so on………
please provide me directions..
Thanks in Advance !!
  2 个评论
Jan
Jan 2012-3-13
I understand the question until "p=2 ((Mod(l,3)) &". What does this mean? I do not get the meaning of the next sentence "the I want..." and "P=0 then P=1 then P=2 then". What is the "Operation" and what does the comma mean in "IndexVariable,P".
Nil
Nil 2012-3-13
Hi Jan Simon..thanks for your comment on question
Here after converting cipher text to bytes, I am calculating index variable (called as p) & formula is MOD(No of Bytes,3).. I have ciphertext length as 5 bytes so Index Variable (p) is 2.. I will always have index varaible values as 0 or 1 or 2 which will be based on no. of Bytes
Say ciphertext is 11001011 01111010 10101010 10011001 01010101
This data is five bytes there for inde variable is 2
11001011 01111010 10101010 10011001 01010101
Now
for first two bits (11) , index variable to be assigned as 2
for next two bits (00), index variable to be assigned as 0
for next two bits (10), index variable to be assigned as 1
for next two bits (11), index variable to be assigned as 2..so on till end of my bits.
------------------------------------------------------
Other Example
Ciphertet with Three Bytes 11001011 01111010 10101010
Index Variable (p) will be 0
for first two bits (11) , index variable to be assigned as 0
for next two bits (00), index variable to be assigned as 1
for next two bits (10), index variable to be assigned as 2
for next two bits (11), index variable to be assigned as 0..
so on till end of my bits..
I hope it clarify my question..I have tried out some coding which is posted yesterday in other post tilted as "loop help" but struggling in assigning index variable to bits

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-3-13
s = '11001011 01111010 10101010 10011001 01010101'
p = rem(numel(regexp(s,' [01]'))+1,3)
k = (0:2)'
s1 = reshape(regexprep(s,' ',''),2,[])'
n = size(s1,1)
N = k(:,ones(fix((n+1)/3)+1,1))
P = N(find(N(:,1) == p)+(0:n-1))'
  3 个评论
Nil
Nil 2012-3-14
hi andrei.it's working as expected thanks for your help.
Here getting s1 as below, I want in following format just to extract bits..
I have tried it with reshape and transpose but not picking up correct bit values
s1 =
11
00
10
11
01
11
10
10
10
10
10
10
10
01
10
01
How to convert s1 as
[1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1]
so
s1(1) will be 1
s1(3) will be 0
s1(5) will be 1

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by