본문 바로가기

디지털포렌식(Digital forensic)/숫자

숫자 대치 암호, 74797357449

반응형

출처: freepik

각 숫자를 다른 숫자로 대체(Exchange)하여 암호화하는 방식으로

대치 암호(Substitution Cipher)는 숫자만을 이용한 가장 간단한 암호화 방법들 중 하나다.

가장 간단한 대치 암호는 숫자 0부터 9까지 각각을 다른 숫자로 대체하는 규칙을 사용할 수 있다.
아래는 숫자 0부터 9까지 랜덤 형식으로 대치하는 Example이다.

 

0 ▶ 7

1 4

2 9

3 1

4 0

5 8

6 3

7 5

8 6

9 2

 

대치 암호를 사용하면 숫자를 암호화하고 복호화할 수 있다.

예를 들어, 숫자 1234는 암호화되면 4910이 되고, 이를 다시 복호화하면 1234로 복원된다..

간단한 대치 암호는 안전하지 않다.

 

아래는 C# 으로 구현한 숫자 대치의 코드다.

 

using System;
using System.Collections.Generic;

class SubstitutionCipher
{
    static Dictionary<int, int> encryptionMap = new Dictionary<int, int>();
    static Dictionary<int, int> decryptionMap = new Dictionary<int, int>();

    static void InitializeMaps()
    {
        int[] originalDigits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        int[] encryptedDigits = { 7, 4, 9, 1, 0, 8, 3, 5, 6, 2 };

        for (int i = 0; i < originalDigits.Length; i++)
        {
            encryptionMap[originalDigits[i]] = encryptedDigits[i];
            decryptionMap[encryptedDigits[i]] = originalDigits[i];
        }
    }

    static string Encrypt(string plaintext)
    {
        InitializeMaps();
        string ciphertext = "";

        foreach (char c in plaintext)
        {
            if (char.IsDigit(c))
            {
                int digit = int.Parse(c.ToString());
                if (encryptionMap.ContainsKey(digit))
                {
                    ciphertext += encryptionMap[digit];
                }
                else
                {
                    ciphertext += c;
                }
            }
            else
            {
                ciphertext += c;
            }
        }

        return ciphertext;
    }

    static string Decrypt(string ciphertext)
    {
        InitializeMaps();
        string plaintext = "";

        foreach (char c in ciphertext)
        {
            if (char.IsDigit(c))
            {
                int digit = int.Parse(c.ToString());
                if (decryptionMap.ContainsKey(digit))
                {
                    plaintext += decryptionMap[digit];
                }
                else
                {
                    plaintext += c;
                }
            }
            else
            {
                plaintext += c;
            }
        }

        return plaintext;
    }

    static void Main(string[] args)
    {
        string plaintext = "1234";

        string encryptedText = Encrypt(plaintext);
        Console.WriteLine("Encrypted: " + encryptedText);

        string decryptedText = Decrypt(encryptedText);
        Console.WriteLine("Decrypted: " + decryptedText);
    }

Encrypted: 4910
Decrypted: 1234


위 코드에서 string plaintext = "1234";를 string plaintext = "01099990112";로 바꾸면

아래와 같이 대치된 값으로 결과가 나온다.

 

Encrypted: 74722227449
Decrypted: 01099990112

 


74797357449

무슨 숫자일까?

728x90