非对称任意进制转换器(安卓)

除了正常进制转换,还可以输入、输出使用不同的数字符号,达成对数值进行加密的效果

在这里插入图片描述
在这里插入图片描述

点我下载APK安装包

使用unity开发。新建一个c#代码文件,把代码覆盖进去,再把代码文件添加给main camera即可。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    string injinzhifuhao = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string injinzhi = @"10";
    string intext = @"12345";
    string outjinzhifuhao = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string outjinzhi1 = @"2";
    string outtext1 = @"";
    private void OnGUI()
    {
        float rect_x = Screen.width * 0.1f;
        float rect_y = Screen.height * 0.1f;
        float rect_w = Screen.width * 0.8f;
        float rect_h = Screen.height * 0.05f;

        GUIStyle style_l = GUI.skin.label;
        style_l.normal.textColor = Color.white;
        style_l.fontSize = (int)(rect_h * 0.8);
        style_l.alignment = TextAnchor.MiddleCenter;

        GUIStyle style_t = GUI.skin.textField;
        style_t.normal.textColor = Color.white;
        style_t.fontSize = (int)(rect_h * 0.8);

        GUIStyle style_b = GUI.skin.button;
        style_b.fontSize = (int)(rect_h * 0.8);
        style_b.alignment = TextAnchor.MiddleCenter;

        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"进制符号", style_l);
        rect_y += rect_h;
        injinzhifuhao = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), injinzhifuhao, style_t);
        rect_y += rect_h;
        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"输入的是几进制", style_l);
        rect_y += rect_h;
        injinzhi = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), injinzhi, style_t);
        rect_y += rect_h;
        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"数值", style_l);
        rect_y += rect_h;
        intext = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), intext, style_t);

        rect_y += rect_h * 2;
        bool butt = GUI.Button(new Rect(rect_x, rect_y, rect_w, rect_h), @"转换", style_b);

        rect_y += rect_h * 2;
        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"转换后的进制符号", style_l);
        rect_y += rect_h;
        outjinzhifuhao = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), outjinzhifuhao, style_t);
        rect_y += rect_h;
        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"转换成几进制", style_l);
        rect_y += rect_h;
        outjinzhi1 = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), outjinzhi1, style_t);
        rect_y += rect_h;
        GUI.Label(new Rect(rect_x, rect_y, rect_w, rect_h), @"数值", style_l);
        rect_y += rect_h;
        outtext1 = GUI.TextField(new Rect(rect_x, rect_y, rect_w, rect_h), outtext1, style_t);

        if (butt)
        {
            int injinzhi_;
            int outjinzhi1_;

            // - - - - - - - - - - - - - - - 纠错 - - - - - - - - - - - - - - - 
            if (injinzhifuhao.Length <= 0) { injinzhifuhao = @"不能没有进制符号"; return; }

            if (int.TryParse(injinzhi, out injinzhi_) == false) { injinzhi = @"无法识别为数字" + injinzhi; return; }
            if (injinzhi_ <= 0) { injinzhi = @"必须是大于零的数字" + injinzhi; return; }

            if (int.TryParse(outjinzhi1, out outjinzhi1_) == false) { outjinzhi1 = @"无法识别为数字" + outjinzhi1; return; }
            if (outjinzhi1_ <= 0) { outjinzhi1 = @"必须是大于零的数字" + outjinzhi1; return; }

            if (injinzhi_ > injinzhifuhao.Length) { injinzhi = @"进制符号太少,无法表示如此大的进制" + injinzhi; return; }

            foreach (var item in intext)
            {
                bool t = false;
                for (int i = 0; i < injinzhi_; i++)
                {
                    if (injinzhifuhao[i] == item) { t = true; break; }
                }
                if (t == false) { intext = @"符号" + item + "不在进制范围的符号中" + intext; return; }
            }

            // - - - - - - - - - - - - - - - 转换 - - - - - - - - - - - - - - - 
            // 用int[]保存intext的每个数字;int[]的元素数量是intext.Length。
            int[] jinzhinum = new int[intext.Length];
            for (int i = 0; i < intext.Length; i++)
            {
                for (int j = 0; j < injinzhifuhao.Length; j++)
                {
                    if (intext[i] == injinzhifuhao[j])
                    {
                        jinzhinum[i] = j;
                    }
                }
            }
            // 对输入值减一,同时输出值加一。
            List<int> outnum = new List<int>();
            outnum.Add(0);
            while (SubOne(ref jinzhinum, injinzhi_))
            {
                AddOne(ref outnum, outjinzhi1_);
            }
            // 数字转换成符号
            outtext1 = @"";
            for (int i = outnum.Count - 1; i >= 0; i--)
            {
                int t = outnum[i];
                string tt = outjinzhifuhao[t].ToString();
                outtext1 = tt + outtext1;
            }
        }


        bool SubOne(ref int[] a, int jinzhi)
        {
            if (a[a.Length - 1] > 0) // 个位数减一
            {
                a[a.Length - 1]--;
                return true;
            }
            else // 需要借位
            {
                for (int i = a.Length - 2; i >= 0; i--)
                {
                    if (a[i] > 0)
                    {
                        a[i]--;
                        for (int j = i + 1; j <= a.Length - 1; j++)
                        {
                            a[j] = jinzhi - 1;
                        }
                        return true;
                    }
                }
                return false; // 传入的数为零,无法继续减一
            }

        }


        void AddOne(ref List<int> a, int jinzhi)
        {
            a[a.Count - 1]++;
            for (int i = a.Count - 1; i >= 0; i--)
            {
                if (a[i] == jinzhi)
                {
                    a[i] = 0;
                    if (i != 0)
                    {
                        a[i - 1]++;
                    }
                    else
                    {
                        a.Insert(0, 1);
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/928754.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【HarmonyOS】鸿蒙应用地理位置获取,地理名称获取

【HarmonyOS】鸿蒙应用地理位置获取&#xff0c;地理名称获取 一、前言 首先要理解地理专有名词&#xff0c;当我们从系统获取地理位置&#xff0c;一般会拿到地理坐标&#xff0c;是一串数字&#xff0c;并不是地理位置名称。例如 116.2305&#xff0c;33.568。 这些数字坐…

OpenGL ES详解——文字渲染

目录 一、文字渲染 二、经典文字渲染&#xff1a;位图字体 1.概念 2.优缺点 三、现代文字渲染&#xff1a;FreeType 1.着色器 2.渲染一行文字 四、关于未来 一、文字渲染 当你在图形计算领域冒险到了一定阶段以后你可能会想使用OpenGL来绘制文字。然而&#xff0c;可能…

C++设计模式之外观模式

动机 下图中左边方案的问题在于组件的客户和组件中各种复杂的子系统有了过多的耦合&#xff0c;随着外部客户程序和各子系统的演化&#xff0c;这种过多的耦合面临很多变化的挑战。 如何简化外部客户程序和系统间的交互接口&#xff1f;如何将外部客户程序的演化和内部子系统…

【Redis篇】 List 列表

在 Redis 中&#xff0c;List 是一种非常常见的数据类型&#xff0c;用于表示一个有序的字符串集合。与传统的链表结构类似&#xff0c;Redis 的 List 支持在两端进行高效的插入和删除操作&#xff0c;因此非常适合实现队列&#xff08;Queue&#xff09;和栈&#xff08;Stack…

RE逆向基础知识及常见题型

通用寄存器 FAX: &#xff08;针对操作数和结果数据的&#xff09;累加器EBX: &#xff08;DS段的数据指针&#xff09;基址寄存器ECX: &#xff08;字符串和循环操作的&#xff09;计数器EDX: &#xff08;I/O指针&#xff09;数据寄存器ESI: &#xff08;字符串操作源指针&a…

APM装机教程(四):山鹰H743飞控四旋翼装机

文章目录 前言一、飞控说明书二、接线三、参数设置四、电机接线和转向 前言 固件版本&#xff1a;Copter 4.5.7 地面站&#xff1a;QGC 遥控器&#xff1a;云卓T10 飞控&#xff1a;山鹰H743 GPS&#xff1a;微空M9 这个飞控的原理图是开源的&#xff0c;网盘链接&#xff1a;…

实验四:MyBatis 的关联映射

目录&#xff1a; 一 、实验目的&#xff1a; 熟练掌握实体之间的各种映射关系。 二 、预习要求&#xff1a; 预习数据库原理中所讲过的一对一、一对多和多对多关系 三、实验内容&#xff1a; 1. 查询所有订单信息&#xff0c;关联查询下单用户信息(注意&#xff1a;因为一…

【C#设计模式(17)——迭代器模式(Iterator Pattern)】

前言 迭代器模式可以使用统一的接口来遍历不同类型的集合对象&#xff0c;而不需要关心其内部的具体实现。 代码 //迭代器接口 public interface Iterator {bool HashNext();object Next(); } //集合接口 public interface Collection {Iterator CreateIterator(); } //元素迭…

MySQL 主从同步一致性详解

MySQL主从同步是一种数据复制技术&#xff0c;它允许数据从一个数据库服务器&#xff08;主服务器&#xff09;自动同步到一个或多个数据库服务器&#xff08;从服务器&#xff09;。这种技术主要用于实现读写分离、提升数据库性能、容灾恢复以及数据冗余备份等目的。下面将详细…

Redis4——持久化与集群

Redis4——持久化与集群 本文讲述了1.redis在内存占用达到限制后的key值淘汰策略&#xff1b;2.redis主从复制原理&#xff1b;3.redis的哨兵模式&#xff1b;4.redis集群模式。 1. 淘汰策略 设置过期时间 expire key <timeout>只能对主hash表中的键设置过期时间。 查…

矩阵转置        ‌‍‎‏

矩阵转置 C语言代码C 语言代码Java语言代码Python语言代码 &#x1f490;The Begin&#x1f490;点点关注&#xff0c;收藏不迷路&#x1f490; 输入一个n行m列的矩阵A&#xff0c;输出它的转置 A T A^T AT。 输入 第一行包含两个整数n和m&#xff0c;表示矩阵A的行数和列数。…

Linux 无界面模式下使用 selenium

文章目录 前言什么是无界面模式&#xff1f;具体步骤安装谷歌浏览器查看安装的谷歌浏览器的版本下载对应版本驱动并安装Python 测试代码 总结个人简介 前言 在 Linux 服务器上运行自动化测试或网页爬虫时&#xff0c;常常需要使用 Selenium 来驱动浏览器进行操作。然而&#x…

windows部署PaddleSpeech详细教程

windows安装paddlespeech步骤&#xff1a; 1. 安装vs c编译环境 对于 Windows 系统&#xff0c;需要安装 Visual Studio 来完成 C 编译环境的安装。 Microsoft C Build Tools - Visual Studio 2. 安装conda conda create -y -p paddlespeech python3.8 conda activate pad…

11.7【miniob】【debug】

这里的vector是实际值&#xff0c;而relation是指针&#xff0c;所以要解引用&#xff0c;*$1&#xff0c;并在最后调用其析构函数 emplace_back 和 push_back 都是用于在容器&#xff08;如 std::vector&#xff09;的末尾添加元素的方法&#xff0c;但它们的工作方式有所不同…

聊聊JVM G1(Garbage First)垃圾收集器

CMS的垃圾回收机制&#xff0c;为什么分为四步https://blog.csdn.net/genffe880915/article/details/144205658说完CMS垃圾回收器&#xff0c;必定要说到目前一般应用项目中都推荐的G1。G1在JDK1.7 update4时引入&#xff0c;在JDK9时取代CMS成为默认的垃圾收集器。它是HotSpot…

一篇文章教会你红外接收模块接收红外遥控信号,附STM32代码示例

目录 一、红外线的通讯原理&#xff1a; &#xff08;1&#xff09;发射端&#xff1a; &#xff08;2&#xff09;接收端&#xff1a; &#xff08;3&#xff09;红外线通信的脉冲频率&#xff1a; &#xff08;4&#xff09;红外线通信&#xff1a; 二、NEC协议介绍&am…

Ignis如何将Tokenization解决方案应用于RWA和实体经济

随着区块链技术的发展&#xff0c;代币化&#xff08;Tokenization&#xff09;逐渐成为连接数字经济与实体经济的重要桥梁。尤其是RWA&#xff08;真实世界资产&#xff09;的概念&#xff0c;近年来成为金融行业的热议话题。Ignis作为Jelurida公司推出的公链平台&#xff0c;…

Linux的用户和权限【Linux操作系统】

文章目录 Linux的用户切换用户普通用户暂时以root用户的权限执行指令如何把一个普通用户加入白名单? 新建用户 Linux权限权限的组成更改权限文件/目录权限的表示方法&#xff1a; umask粘滞位添加粘滞位的方法 Linux的用户 Linux下有两种⽤⼾&#xff1a;超级用户&#xff08…

【专题】计算机网络之运输层(传输层)

1. 运输层协议概述 1.1 进程之间的通信 (1) 运输层的作用 运输层提供进程间的逻辑通信。 运输层的屏蔽作用&#xff1a; 运输层向高层用户屏蔽了下面网络核心的细节&#xff08;如网络拓扑、所采用的路由选择协议等&#xff09;&#xff0c;使应用进程看见的就是好像在两个运…

【C#之WPF+OllamaSharpe实现离线AI对话】

一、前言 C#之WPFOllamaSharpe实现离线AI对话&#xff0c;调用Markdig格式化显示交互结果. 此程序默认你已经安装好了Ollama。 在运行前需要线安装好Ollama,如何安装请自行搜索 Ollama下载地址&#xff1a; https://ollama.org.cn Ollama模型下载地址&#xff1a; https:/…