シーザー暗号(Caesar cipher)作ってみた

暗号技術のはなし―シーザー暗号から公開鍵暗号まで
 シーザー暗号作ってみました。
twitter投稿機能も付けてみたけど、ちゃんと動くといいな……。


説明はこっちに任せるとして→シーザー暗号 - Wikipedia


使い方
1.スタートボタンで開始
2.平文ボックスに暗号化したい文章を入れる
3.シフト数ボックスに数字(半角で1桁~3桁)を入れる
4.twitter投稿ボタンで暗号文を投稿




using UnityEngine;
using System.Collections;

public class titlebutton : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void OnClick()
    {
        Application.LoadLevel("main");
    }
}
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class cript : MonoBehaviour {

    public Text obj_ClaerText;
    public Text obj_ShiftNumber;
    public Text obj_CipherText;

    bool isClearT;
    string texClearT;

    bool isShiftN;
    int numShiftN;

    // Use this for initialization
	void Start () {
        this.isClearT = false;
        this.isShiftN = false;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void CleartextCheck(string str)
    {

        if (str.Length == 0)
        {
            this.isClearT = false;
            return;
        }
        else
        {
            this.isClearT = true;
            this.texClearT = str;
        }

        this.Crypting();
    }

    public void ShiftNumberCheck(string str)
    {
        if (str.Length == 0)
        {
            this.isShiftN = false;
            return;
        }

        foreach (char c in str)
        {
            if (c < '0' | c > '9')
            {
                this.isShiftN = false;
                return;
            }
        }

        this.isShiftN = true;
        this.numShiftN = int.Parse(str);

        this.Crypting();
    }

    private void Crypting()
    {

        if (this.isCrypt() == true)
        {
            string citxt = "";

            for (int i = 0; i < this.texClearT.Length; i++)
            {
                citxt += (char)(this.texClearT[i] + this.numShiftN);
            }

            this.obj_CipherText.text = citxt;
        }
        else
        {
            this.obj_CipherText.text = "";
        }
    }

    private bool isCrypt()
    {
        if (this.isClearT == true & this.isShiftN == true) return true;
        else return false;
    }
    
}
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class toukou : MonoBehaviour {

    public Text obj_ChiperText;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void PostTwitter()
    {
        if (this.obj_ChiperText.text.Length > 0)
        {
            Application.OpenURL("http://twitter.com/intent/tweet?text=" + WWW.EscapeURL(this.obj_ChiperText.text + " http://bit.ly/1fyme7C " + " #シーザー暗号"));
        }
    }
}


シーザー 吟撰ビーフ チーズ 100g × 24個入り(CE28N)

シーザー 吟撰ビーフ チーズ 100g × 24個入り(CE28N)