C#์„ ์ด์šฉํ•œ ์ž๋™ํ™” ๋ณด์•ˆ์„ ์œ„ํ•œ ๊ฐ„๋‹จํ•œ ์•”ํ˜ธํ™” ๊ธฐ๋ฒ•(Enhancing Automation Security with Simple Encryption Techniques)

2024. 6. 12. 11:58ใ†Development๐Ÿ‘ฉ๐Ÿป‍๐Ÿฆณ/C#

์•”ํ˜ธํ™”์˜ ๋‹จ๊ณ„
[์˜ˆ์ œ 3] 1์ฐจ์› ๋ฐฐ์—ด์„ ์ด์šฉํ•œ N๊ธ€์ž ์ „์น˜์•”ํ˜ธ ํ”„๋กœ๊ทธ.zip
0.04MB
์•”ํ˜ธํ™”๋ฆฌํŒฉํ† ๋ง.zip
0.04MB

์•”ํ˜ธํ™”์˜ ํ•„์š”์„ฑ ๋ฐ ์šฉ๋„ ( Necessity and purpose of encryption )

 

๊ณต์ • ์ž๋™ํ™”์—์„œ ์•”ํ˜ธํ™” ๋ฐ ๋ฐ์ดํ„ฐ ์„ž๊ธฐ ๊ธฐ์ˆ ์€ ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ, ์•ˆ์ „ํ•œ ํ†ต์‹ , ํ”„๋กœ์„ธ์Šค ๋ณด์•ˆ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

1. ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ ๋ฐ ๊ธฐ๋ฐ€์„ฑ ์œ ์ง€

  • ์ƒ์‚ฐ ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ: ์ƒ์‚ฐ๋Ÿ‰, ๊ณต์ • ์‹œ๊ฐ„, ํ’ˆ์งˆ ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ ๋“ฑ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์•”ํ˜ธํ™”ํ•˜์—ฌ ๋ณดํ˜ธ.
  • ๊ธฐ๊ณ„ ๊ฐ„ ์•ˆ์ „ํ•œ ํ†ต์‹ : ๊ธฐ๊ณ„ ๊ฐ„ ํ†ต์‹  ๋ฐ์ดํ„ฐ๋ฅผ ์•”ํ˜ธํ™”ํ•˜์—ฌ ๋„์ฒญ ๋ฐฉ์ง€.

2. ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ ๋ฐ ์ธ์ฆ

  • ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ ๊ฒ€์ฆ: ๋ฐ์ดํ„ฐ ์ „์†ก ์ค‘ ๋ณ€์กฐ ์—ฌ๋ถ€ ํ™•์ธ.
  • ์‚ฌ์šฉ์ž ์ธ์ฆ ๋ฐ ์ ‘๊ทผ ์ œ์–ด: ์‚ฌ์šฉ์ž ์ธ์ฆ ์‹œ ์•”ํ˜ธํ™”๋œ ํ† ํฐ ์‚ฌ์šฉ.

3. ํ”„๋กœ์„ธ์Šค ๋ณด์•ˆ ๋ฐ ์ด์ƒ ๊ฐ์ง€

  • ํ”„๋กœ์„ธ์Šค ๋ณด์•ˆ ๊ฐ•ํ™”: ์•”ํ˜ธํ™”๋œ ๋ช…๋ น์–ด๋กœ ํŠน์ • ํ”„๋กœ์„ธ์Šค ๋ณดํ˜ธ.
  • ์ด์ƒ ๊ฐ์ง€ ์‹œ์Šคํ…œ: ์•”ํ˜ธํ™”๋œ ๋ฐ์ดํ„ฐ๋ฅผ ํ†ตํ•ด ๋น„์ •์ƒ ํ™œ๋™ ํƒ์ง€.

4. ๊ณต๊ธ‰๋ง ๋ณด์•ˆ

  • ๊ณต๊ธ‰๋ง ๋‚ด ๋ฐ์ดํ„ฐ ๋ณดํ˜ธ: ๊ณต๊ธ‰๋ง ์ „์ฒด์—์„œ ๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™”.

5. ์›๊ฒฉ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ์ œ์–ด

  • ์›๊ฒฉ ์ œ์–ด ์‹œ์Šคํ…œ ๋ณดํ˜ธ: ์›๊ฒฉ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ์ œ์–ด ์‹œ ๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™”.

์•”ํ˜ธํ™” ๋ฐฉ์‹

ํ˜„์žฌ ๊ตฌํ˜„๋œ ์•”ํ˜ธํ™” ๋ฐฉ์‹์€ ๊ธฐ๋ณธ์ ์ธ ๋‹จ์ˆœ ์น˜ํ™˜ ์•”ํ˜ธํ™”์ž…๋‹ˆ๋‹ค. ์ด๋Š” ๊ฐ ๋ฌธ์ž๋ฅผ ํŠน์ • ๊ทœ์น™์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๋ฌธ์ž๋กœ ๋Œ€์ฒดํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ํ–ฅํ›„ ๋‹ค์ค‘ ์น˜ํ™˜ ์•”ํ˜ธํ™”, ๋ธ”๋ก ์•”ํ˜ธํ™”, ๋Œ€์นญ ํ‚ค ์•”ํ˜ธํ™”, ๋น„๋Œ€์นญ ํ‚ค ์•”ํ˜ธํ™”, ์–‘์ž ์•”ํ˜ธํ™” ๋“ฑ์˜ ๊ณ ๊ธ‰ ์•”ํ˜ธํ™” ๊ธฐ๋ฒ• ๋„์ž…์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ASCII ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•œ ๊ฐ„๋‹จํ•œ ์•”ํ˜ธํ™” ์˜ˆ์ œ

ASCII ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•œ ์•”ํ˜ธํ™”๋Š” ๋ฌธ์ž ๋ฐ์ดํ„ฐ๋ฅผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ ๊ณผ์ •์„ ํ†ตํ•ด ์•”ํ˜ธํ™”์˜ ๊ธฐ์ดˆ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ ์ฝ”๋“œ: C#

csharp์ฝ”๋“œ ๋ณต์‚ฌ
char c = 'A';         // ๋ฌธ์ž 'A'
int asciiValue = (int)c;  // ASCII ์ฝ”๋“œ ๊ฐ’ 65
char newChar = (char)asciiValue; // ๋‹ค์‹œ ๋ฌธ์ž 'A'๋กœ ๋ณ€ํ™˜

Console.WriteLine(asciiValue); // ์ถœ๋ ฅ: 65
Console.WriteLine(newChar);    // ์ถœ๋ ฅ: A

ํ•ต์‹ฌ ๊ตฌํ˜„ ๊ณผ์ • ์š”์•ฝ

1. ์ž…๋ ฅ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
if (textBox1.Text == "") { /* ๊ฒฝ๊ณ  1 */ }
if (textBox4.Text == "") { /* ๊ฒฝ๊ณ  2 */ }
if (textBox5.Text == "") { /* ๊ฒฝ๊ณ  3 */ }
if (int.Parse(textBox4.Text) < 2 || int.Parse(textBox4.Text) > 7) { /* ๊ฒฝ๊ณ  4 */ }
if (int.Parse(textBox4.Text) != textBox5.Text.Length) { /* ๊ฒฝ๊ณ  5 */ }

2. ์„ž์„ ์ˆœ์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
for (int j = 0; j < iCutting_Giri; j++) {
    int iTemp = Convert.ToInt16(sSunceo[j]);
    if (iTemp < 1 || iTemp > iCutting_Giri) { /* ๊ฒฝ๊ณ  6 */ }
    for (int k = j + 1; k < iCutting_Giri; k++) {
        if (sSunceo[j] == sSunceo[k]) { /* ๊ฒฝ๊ณ  7 */ }
    }
}
// Check for three consecutive numbers in sequence
bool consecutiveFound = false;
for (int i = 0; i < iCutting_Giri - 2; i++) {
    int a = Convert.ToInt16(sSunceo[i]);
    int b = Convert.ToInt16(sSunceo[i + 1]);
    int c = Convert.ToInt16(sSunceo[i + 2]);

    if ((b == a + 1 && c == b + 1) || (b == a - 1 && c == b - 1)) {
        consecutiveFound = true;
        break;
    }
}

if (consecutiveFound) {
    /* ๊ฒฝ๊ณ  9 */
}

3. ๋ฌธ์ž์—ด์„ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ ๋ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
for (int iCount = 0; iCount < iMunjang_Giri; iCount++) {
    sTemp = textBox1.Text.Substring(iCount, 1);
    char cTemp = Convert.ToChar(sTemp);
    int iTemp = Convert.ToInt32(cTemp);
    if (iTemp < 97 || (iTemp > 122 && iTemp < 40000)) { /* ๊ฒฝ๊ณ  10 */ }
}

4. ํŒจ๋”ฉ ์ž‘์—…

csharp์ฝ”๋“œ ๋ณต์‚ฌ
if (iMunjang_Giri % iCutting_Giri != 0) {
    int iPadding_Giri = iCutting_Giri - (iMunjang_Giri % iCutting_Giri);
    sTemp = textBox1.Text.Substring(iMunjang_Giri - 1, 1);
    char cTemp = Convert.ToChar(sTemp);
    int iTemp = Convert.ToInt32(cTemp);
    if (iTemp > 96 && iTemp < 123)
        textBox1.Text += sEng_Pad.Substring(0, iPadding_Giri);
    else
        textBox1.Text += sKor_Pad.Substring(0, iPadding_Giri);
}

5. ๋ฌธ์ž์—ด ์„ž๊ธฐ ๋ฐ ์•”ํ˜ธ๋ฌธ ์ƒ์„ฑ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
for (int j = 0; j < iMunjang_Giri; j += iCutting_Giri) {
    for (int k = 0; k < iCutting_Giri; k++)
        sTempArray[k] = sMunjang[j + k];
    for (int y = 0; y < iCutting_Giri; y++)
        sMunjang[j + y] = sTempArray[Convert.ToInt16(sSunceo[y]) - 1];
}
textBox2.Text = "";
for (int iCount = 0; iCount < iMunjang_Giri; iCount++) {
    char cTemp = Convert.ToChar(sMunjang[iCount]);
    int iTemp = Convert.ToInt32(cTemp);
    if (iTemp > 96 && iTemp < 123)
        textBox2.Text += Convert.ToChar(iTemp - (97 - 65));
    else
        textBox2.Text += sMunjang[iCount];
}

์•”ํ˜ธํ™” ์˜ˆ์ œ ์ฝ”๋“œ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
using System;
using System.Text;

public class SimpleEncryption {
    public static string Encrypt(string plainText, string key) {
        char[] chars = plainText.ToCharArray();
        int[] order = Array.ConvertAll(key.ToCharArray(), c => (int)char.GetNumericValue(c) - 1);
        StringBuilder encrypted = new StringBuilder();

        for (int i = 0; i < chars.Length; i += order.Length) {
            char[] segment = new char[order.Length];
            for (int j = 0; j < order.Length; j++) {
                if (i + j < chars.Length) {
                    segment[order[j]] = chars[i + j];
                } else {
                    segment[order[j]] = ' '; // Padding with spaces
                }
            }
            encrypted.Append(segment);
        }
        return encrypted.ToString();
    }

    public static void Main() {
        string plainText = "hellothere";
        string key = "312";

        string encryptedText = Encrypt(plainText, key);
        Console.WriteLine("Encrypted: " + encryptedText);
    }
}

ํ•ดํ‚น(๋ณตํ˜ธํ™”) ์ฝ”๋“œ ์˜ˆ์ œ

csharp์ฝ”๋“œ ๋ณต์‚ฌ
using System;
using System.Text;

public class SimpleDecryption {
    public static string Decrypt(string encryptedText, string key) {
        char[] chars = encryptedText.ToCharArray();
        int[] order = Array.ConvertAll(key.ToCharArray(), c => (int)char.GetNumericValue(c) - 1);
        int[] reverseOrder = new int[order.Length];

        // Creating reverse order
        for (int i = 0; i < order.Length; i++) {
            reverseOrder[order[i]] = i;
        }

        StringBuilder decrypted = new StringBuilder();

        for (int i = 0; i < chars.Length; i += order.Length) {
            char[] segment = new char[order.Length];
            for (int j = 0; j < order.Length; j++) {
                if (i + j < chars.Length) {
                    segment[j] = chars[i + reverseOrder[j]];
                }
            }
            decrypted.Append(segment);
        }
        return decrypted.ToString();
    }

    public static void Main() {
        string encryptedText = "elho htleer"; // Encrypted form of "hellothere" with key "312"
        string key = "312";

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

์ฝ”๋“œ ์„ค๋ช…

  1. Encrypt ํ•จ์ˆ˜:
    • ํ‰๋ฌธ(plainText)๊ณผ ํ‚ค(key)๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ์•”ํ˜ธํ™”๋œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
    • ํ‚ค๋ฅผ ํ†ตํ•ด ๋ฌธ์ž์˜ ์ˆœ์„œ๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , ํ•ด๋‹น ์ˆœ์„œ์— ๋งž์ถฐ ๋ฌธ์ž๋ฅผ ์žฌ๋ฐฐ์—ดํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฌธ์ž ๊ธธ์ด๋ณด๋‹ค ์งง์€ ๊ฒฝ์šฐ ๊ณต๋ฐฑ์œผ๋กœ ํŒจ๋”ฉํ•ฉ๋‹ˆ๋‹ค.
  2. Decrypt ํ•จ์ˆ˜:
    • ์•”ํ˜ธํ™”๋œ ํ…์ŠคํŠธ(encryptedText)์™€ ํ‚ค(key)๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ๋ณตํ˜ธํ™”๋œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
    • ํ‚ค๋ฅผ ํ†ตํ•ด ๋ฌธ์ž์˜ ์›๋ž˜ ์ˆœ์„œ๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” reverseOrder ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
    • ์›๋ž˜ ์ˆœ์„œ์— ๋”ฐ๋ผ ๋ฌธ์ž๋ฅผ ์žฌ๋ฐฐ์—ดํ•˜์—ฌ ๋ณตํ˜ธํ™”๋œ ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

ASCII ์ฝ”๋“œ ํ™œ์šฉ

  • Convert.ToInt16 ๋ฐ char.GetNumericValue๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž ๋ฐ์ดํ„ฐ๋ฅผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  • StringBuilder๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด์„ ํšจ์œจ์ ์œผ๋กœ ์กฐ๋ฆฝํ•ฉ๋‹ˆ๋‹ค.

์žฅ๋‹จ์ 

์žฅ์ 

  • ๊ฐ„๋‹จํ•œ ์ดํ•ด: ๊ธฐ๋ณธ์ ์ธ ์•”ํ˜ธํ™” ๋ฐ ๋ณตํ˜ธํ™” ๊ฐœ๋…์„ ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ASCII ์ฝ”๋“œ ํ™œ์šฉ: ๋ฌธ์ž ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹จ์ 

  • ๋ณด์•ˆ ์ˆ˜์ค€ ๋‚ฎ์Œ: ๋งค์šฐ ๋‹จ์ˆœํ•œ ์•”ํ˜ธํ™” ๋ฐฉ๋ฒ•์œผ๋กœ, ํ˜„๋Œ€์ ์ธ ๋ณด์•ˆ ์š”๊ตฌ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.
  • ์‹ค์ œ ์ ์šฉ์˜ ํ•œ๊ณ„: ํ•™์Šต ๋ชฉ์  ์™ธ์— ์‹ค๋ฌด์—์„œ๋Š” ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๋น„ํšจ์œจ์„ฑ ๋ฐ ๊ฐœ์„ ์ 

  1. goto ๋ฌธ ์‚ฌ์šฉ: ์ œ์–ด ๊ตฌ์กฐ๋ฅผ ํ†ตํ•ด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๊ฐœ์„ .
  2. ์ˆœ์„œ ๊ฒ€์‚ฌ: ์ค‘๋ณต ๊ฒ€์‚ฌ๋ฅผ ์ตœ์†Œํ™”.
  3. ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ฒ€์‚ฌ: ํ•จ์ˆ˜๋ฅผ ํ†ตํ•œ ์ฝ”๋“œ ๊ฐ„๊ฒฐํ™”.
  4. ํ•˜๋“œ์ฝ”๋”ฉ๋œ ํŒจ๋”ฉ ๋ฌธ์ž: ์œ ์—ฐ์„ฑ ์ฆ๋Œ€.

๊ฐœ์„ ๋œ ์˜ˆ์‹œ: Strategy ํŒจํ„ด ์ ์šฉ

์ธํ„ฐํŽ˜์ด์Šค ์ •์˜

csharp์ฝ”๋“œ ๋ณต์‚ฌ
public interface IEncryptionStrategy {
    string Encrypt(string plainText, int segmentLength, string shuffleOrder);
}

๋‹จ์ˆœ ์ „์น˜ ์•”ํ˜ธํ™” ์ „๋žต ๊ตฌํ˜„

csharp์ฝ”๋“œ ๋ณต์‚ฌ
public class SimpleTranspositionEncryption : IEncryptionStrategy {
    public string Encrypt(string plainText, int segmentLength, string shuffleOrder) {
        // ํŒจ๋”ฉ ์ฒ˜๋ฆฌ
        plainText = PadPlainText(plainText, segmentLength);
        // ํ‰๋ฌธ์„ ์„ธ๊ทธ๋จผํŠธ๋กœ ๋‚˜๋ˆ”
        string[] segments = SplitTextIntoSegments(plainText, segmentLength);
        // ์„ธ๊ทธ๋จผํŠธ๋ฅผ ์„ž์Œ
        string[] shuffledSegments = ShuffleSegments(segments, shuffleOrder);
        // ์•”ํ˜ธ๋ฌธ ์ƒ์„ฑ
        return CreateCipherText(shuffledSegments);
    }

    private string PadPlainText(string plainText, int segmentLength) {
        int paddingLength = segmentLength - (plainText.Length % segmentLength);
        if (paddingLength < segmentLength) {
            char paddingChar = plainText[plainText.Length - 1] < 128 ? 'x' : 'ํ•˜';
            plainText += new string(paddingChar, paddingLength);
        }
        return plainText;
    }

    private string[] SplitTextIntoSegments(string text, int segmentLength) {
        int segmentCount = text.Length / segmentLength;
        string[] segments = new string[segmentCount];
        for (int i = 0; i < segmentCount; i++) {
            segments[i] = text.Substring(i * segmentLength, segmentLength);
        }
        return segments;
    }

    private string[] ShuffleSegments(string[] segments, string shuffleOrder) {
        string[] shuffledSegments = new string[segments.Length];
        for (int i = 0; i < segments.Length; i++) {
            char[] shuffledSegment = new char[segments[i].Length];
            for (int j = 0; j < segments[i].Length; j++) {
                shuffledSegment[j] = segments[i][shuffleOrder[j] - '1'];
            }
            shuffledSegments[i] = new string(shuffledSegment);
        }
        return shuffledSegments;
    }

    private string CreateCipherText(string[] segments) {
        string cipherText = string.Join("", segments);
        return cipherText.ToUpper();
    }
}

Form1 ํด๋ž˜์Šค์˜ ์ˆ˜์ •

csharp์ฝ”๋“œ ๋ณต์‚ฌ
public partial class Form1 : Form {
    private IEncryptionStrategy encryptionStrategy;

    public Form1() {
        InitializeComponent();
        encryptionStrategy = new SimpleTranspositionEncryption();
    }

    private void buttonEncrypt_Click(object sender, EventArgs e) {
        if (IsValidInput()) {
            string cipherText = encryptionStrategy.Encrypt(
                textBoxPlain.Text,
                int.Parse(textBoxSegmentLength.Text),
                textBoxShuffleOrder.Text
            );
            textBoxCipher.Text = cipherText;
        }
    }

    private bool IsValidInput() {
        if (string.IsNullOrEmpty(textBoxPlain.Text)) {
            ShowError("ํ‰๋ฌธ์„ ์ž…๋ ฅํ•˜๊ณ  ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์„ธ์š”.", "[ ๊ฒฝ๊ณ  1 ]");
            textBoxPlain.Focus();
            return false;
        }
        if (string.IsNullOrEmpty(textBoxSegmentLength.Text)) {
            ShowError("๋‚˜๋ˆŒ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ ์„œ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์„ธ์š”.", "[ ๊ฒฝ๊ณ  2 ]");
            textBoxSegmentLength.Focus();
            return false;
        }
        if (string.IsNullOrEmpty(textBoxShuffleOrder.Text)) {
            ShowError("์„ž์„ ์ˆœ์„œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ ์„œ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด์„ธ์š”.", "[ ๊ฒฝ๊ณ  3 ]");
            textBoxShuffleOrder.Focus();
            return false;
        }
        if (!int.TryParse(textBoxSegmentLength.Text, out int segmentLength) || segmentLength < 2 || segmentLength > 7) {
            ShowError("๋‚˜๋ˆŒ ๊ธธ์ด๋Š” 2~7 ์‚ฌ์ด์˜ ๊ฐ’์ž…๋‹ˆ๋‹ค.", "[ ๊ฒฝ๊ณ  4 ]");
            textBoxSegmentLength.Focus();
            textBoxSegmentLength.SelectAll();
            return false;
        }
        if (textBoxShuffleOrder.Text.Length != segmentLength) {
            ShowError("๋‚˜๋ˆŒ ๊ธธ์ด์™€ ์„ž์„ ์ˆœ์„œ์˜ ๊ธธ์ด๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.", "[ ๊ฒฝ๊ณ  5 ]");
            textBoxShuffleOrder.Focus();
            textBoxShuffleOrder.SelectAll();
            return false;
        }
        if (!IsValidShuffleOrder(textBoxShuffleOrder.Text, segmentLength)) {
            return false;
        }
        return true;
    }

    private void ShowError(string message, string title) {
        MessageBox.Show(message, title);
    }

    private bool IsValidShuffleOrder(string shuffleOrder, int segmentLength) {
        bool[] isUsed = new bool[segmentLength];

        for (int i = 0; i < segmentLength; i++) {
            if (!int.TryParse(shuffleOrder[i].ToString(), out int order) || order < 1 || order > segmentLength) {
                ShowError("์„ž์„ ์ˆœ์„œ๋Š” 1๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๋‚˜๋ˆŒ ๊ธธ์ด๋ณด๋‹ค ํด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", "[ ๊ฒฝ๊ณ  6 ]");
                textBoxShuffleOrder.Focus();
                textBoxShuffleOrder.SelectionStart = i;
                textBoxShuffleOrder.SelectionLength = 1;
                return false;
            }
            if (isUsed[order - 1]) {
                ShowError("๋™์ผํ•œ ์ˆœ์„œ๊ฐ€ ๋‘๋ฒˆ ์ž…๋ ฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", "[ ๊ฒฝ๊ณ  7 ]");
                textBoxShuffleOrder.Focus();
                textBoxShuffleOrder.SelectionStart = i;
                textBoxShuffleOrder.SelectionLength = 1;
                return false;
            }
            isUsed[order - 1] = true;
        }
        return true;
    }
}

์ด ์ ‘๊ทผ ๋ฐฉ์‹์€ ์•”ํ˜ธํ™” ๊ฐœ๋…์˜ ๊ธฐ์ดˆ๋ฅผ ์ดํ•ดํ•˜๋Š” ๋ฐ ์œ ์šฉํ•˜์ง€๋งŒ, ์‹ค์ œ ๋ณด์•ˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—๋Š” ๋” ๊ฐ•๋ ฅํ•œ ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.