简体   繁体   English

从字符串中删除字符

[英]Removing the character from String

I'm encrypting the text by using Vigenere cipher.我正在使用 Vigenere 密码加密文本。 Usually, I this method the key has to shorter than the original text, but what if the key is longer than the text?通常,我这个方法key必须比原始文本短,但是如果key比文本长怎么办? Can someone help me figure out ho to make the key equal to the text有人可以帮我弄清楚如何使密钥等于文本

NOTE: I already know how to encrypt the text.注意:我已经知道如何加密文本。

The expected output should be: CIPHER_预期的输出应该是:CIPHER_

import java.util.Arrays;

public class Test {

public static void main (String [] a) {  
String bellasoStr = "CIPHER_IS_LONGER_THAN_THE_PLAIN_TEXT";//key
String plainText = "TESTING";//String


int x = plainText.length();
int y = bellasoStr.length();
String bellasoEncrypted = "";


char[] chars1 = bellasoStr.toCharArray();


if (!bellasoStr.equals(plainText)) {
    for (int i = 0; i < plainText.length(); i++) {
        bellasoStr = bellasoStr.substring(0, bellasoStr.length() - i);

    }
    System.out.println(bellasoStr);
}

Use the following statement in a controlled way以受控方式使用以下语句

bellasoStr = bellasoStr.substring(0, bellasoStr.length() - i);

ie IE

if(bellasoStr.length() <= plainText.length()) {
    bellasoStr = bellasoStr.substring(0,  bellasoStr.length() - i);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM