English 中文(简体)
剖腹产:如何从胎体中删除随机信件
原标题:Caesars Cipher with a twist: how to remove random letters from a string

我正致力于改变 Java文中的剖腹产。 变化是,每2个空间都生成和插入随机信函。 我的加密工作只是罚款。 我的加密大多在发挥作用。 我的方案对其加以加密,但我不知道如何去除随机信件。 我写了撤销这些信件的职能,我目前的法典如下:

let decryptedMessage = seoekx tbhea mtidrniughkt

function finalMessage (decryptedMessage) {
    let finalMessage = "";
    for (let i = 1; i < decryptedMessage.length - 1; i++) {
        if (i % 2 === 0) {
            finalMessage += decryptedMessage.replace(decryptedMessage[i],"");
        }
        else {
            finalMessage += decryptedMessage[i];
        }
    }
    return finalMessage;
}

const finalMessageResult = finalMessage(decryptedMessageResult);
console.log(`The final decrypted message is ${finalMessageResult}`);

这是我的看法:

eseekx tbhea mtidrniughkteseoex tbhea mtidrniughktxseoekxtbhea mtidrniughkttseoekx thea mtidrniughkthsoekx tbhea mtidrniughktaseoekxtbhea mtidrniughktmseoekx bhea mtidrniughktiseoekx tbhea mtirniughktrseoekx tbhea mtidriughktiseoekx tbhea mtidrnighktgseoekx tbea mtidrniughktk

我认为,我需要把最后的婚姻从 lo中解放出来,但我不知道如何这样做,因为我感到,发言是否应该站在通过电文 lo上。

Any help would be appreciated.

我认为,我需要作一个发言。 我头部的逻辑是使用2%=0,然后用“”取代这一要素。 但显然,我所领导的以及正在执行的东西并不相同。 我期望该守则将随机信件从扼杀中删除,从而形成可读的信息。

问题回答

象你的调子一样,算术只是一小差一点,我们像你们一样,对算法进行过度思考! 引证:

let decryptedMessage = "seoekx tbhea mtidrniughkt";

function finalMessage (decryptedMessage) {
    let finalMessage = "";
    
    for (let i = 0; i < decryptedMessage.length; i++) {
        if ((i + 1) % 3 !== 0) {
            finalMessage += decryptedMessage[i];
        }
    }
    return finalMessage;
}

const finalMessageResult = finalMessage(decryptedMessage);
console.log(`The final decrypted message is ${finalMessageResult}`);

我做了一些改动:

  • Start your iterator at 0, because the first index of your string is 0
  • You want to mod 3, because you re removing every 3rd letter
  • Your algorithm was a bit unnecessarily complicated! This just adds every letter but the third letter to your output string
  • To compensate starting i at 0, I simply check i + 1

产出:<代码> 最终加密信息在午夜查询





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签