1

以下是我目前的功能

________Sbox 函数______

> Sbox2 <- function(b)
>         {   b <- unlist(strsplit(b, ""))   tempVal <- unbinary(paste(b[2:4], collapse = ''))   tempRet <- ifelse((b[1] ==
> "0"), S11[tempVal + 1], S12[tempVal + 1])   return(tempRet) } S11 <-
> binary(c(4, 0, 6, 5, 7, 1, 3 ,2)) S12 <- binary(c(5, 3, 0, 7, 6, 2, 1,
> 4))


_______expand Function (provided)_____

expand <- function(v) {
  ev <- vector(mode="character")
  swap(v[3], v[4])
  ev[1:4] <- v[1:4]
  ev[5:8] <- v[3:6]
  return(ev)
}

___轮 1 功能___

round1 <- function(b,k){
    #Divide the block into two equal halves called L0 and R0. 
    b <- (unlist(strsplit(b, "")))
    k <- (unlist(strsplit(k, "")))
    L0 <- b[1:6]
    R0 <- b[7:12]
    #Create two sub keys K1 containing the first 8 digits of K and K2 that contains the last 8 digits of K.
    K1 <- k[1:8]
    K2 <- k[2:9]
    #Expand R0 from 6 t o 8 bits and call it ER0
    ER0 <- expand(R0)
    #Take the XOR of the result of ER0 with K1. Store the first 4 bits in a variable called block1 and the last 4 bits in a variable called 
    fullblock <- bitwXor(ER0,K1)
    block1 <- fullblock[1:4]
    block2 <- fullblock[4:8]
    # Call Sbox1() with block1 as its parameter.
    # Call Sbox2() with block2 as its parameter.
    b1 <- Sbox1(block1)
    b2 <- Sbox2(block2)
    # Concatenate the results of e) and f) and store the result in a variable called FR0.
    FR0 <- c(b1,b2)
    #Take the XOR of FR0 and L0 and store the results in R1.
    R1 <- bitwXor(FR0,L0)
    #Store R0 to L1
    L1 <- R0
    #Return L1 concatenated to R1
    return(c(L1, R1))

} round1('000001010111','001101100')


问题:运行我的 round1() 函数时,bitwXor 函数不断重复此错误:bitwXor(ER0, K1) 中的错误:'bitwXor' 中未实现类型'字符'

我尝试使用不同的数据类型,但似乎没有任何效果?是否只是数据类型问题

PS如果它有助于我输入函数,如:round1(“000001010111”,“001101100”)

4

0 回答 0