斯巴达手杖Skytail(加密)

package j12;

import java.io.BufferedReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


class Skytail {
    public String Skytail_encryption(String str) {   //加密
        String str0 = str.replace(" ", "");     //去除空格的纯字母

        int line = str0.length() / 2;      //条杠个数

        int length = str0.length() / 2 * 4 + str0.length() % 2;
        char[] a = new char[length];

        int index = 0;    //指向str0的下标
        int i = 3;        //指向a数组的i下标

        for (int j = 0; j < line; j++) {    //录入正面字母到数组
            a[i] = str0.charAt(j);
            i += 4;
        }

        i = 0;
        for (int j = line; j < str0.length(); j++) {    //录入侧面字母到数组
            a[i] = str0.charAt(j);
            i += 4;
        }

        StringBuffer sb=new StringBuffer();
        i = 0;

        index = 0;
        while (i < length) {
            if (i == 0) {
                sb.append(a[i]);
                index++;
                i += 3;
                continue;
            }
            sb.append(a[i]);
            index++;
            i++;
            sb.append(a[i]);
            index++;
            i += 3;
        }

        return sb.toString();

    }
}


public class j13 {
    public static void main(String args[]) {
        while (true) {
            Scanner reader = new Scanner(System.in);

            System.out.print("请输入消息:");
            String str = reader.nextLine();      //录入的字符串

            Skytail s = new Skytail();
            System.out.print("密文为:");
            System.out.println(s.Skytail_encryption(str));
        }
    }
}

测试结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值