【问题标题】:How to extract and pair up bits of a key?如何提取和配对密钥位?
【发布时间】:2017-03-27 09:11:53
【问题描述】:
function k = q43042300

key=input('Enter the key','s');
keyarr=dec2bin(key,8)

temp=1;
v=char(zeros(1,16*8));
for i=1 :16
  for j=1:8
    v(temp)=keyarr(i,j);
    temp=temp+1;
  end
end
temp=1;

for i=1:16:128
  k(temp)=v(i:i+15) % Error: Subscripted assignment dimension mismatch.
  temp=temp+1
end

我想得到一个像'abcdefghijklmnop' 这样的键作为输入,然后我想将字符转换为二进制数字(这样我得到 128 位)。 然后我想将每个连续的 16 位配对到一个字段中,但这会出错。

【问题讨论】:

  • 这是什么错误?
  • 分配应该包含相同数量的元素
  • 您的代码中有多个分配。这是哪条线来的。请详细描述您的问题。另外,我不明白你的计划。你能给出一些示例输入和输出吗? k 是什么?它被使用但从未定义。

标签: matlab encryption input passwords grouping


【解决方案1】:

如果我正确理解了您的请求(即将提供的密钥转换为 8 组 16 位二进制数字),这就是您想要做的:

k = reshape(dec2bin(input('Enter the key: ','s'),8).',16,[]).';

你不需要循环,只需要一些重塑。

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 2012-07-13
    • 2014-10-21
    • 2018-12-30
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多