ctfs
  • 👋Hello!
  • 🏴Practice
    • 🌐Cryptohack
      • Introduction
      • General
        • Encoding
        • XOR
        • Mathematics
        • Data Formats
      • Symmetric Ciphers
        • How AES Works
        • Symmetric Starter
        • Block Ciphers 1
        • Stream Ciphers
      • Mathematics
        • Modular Math
        • Lattices
      • RSA
        • Starter
        • Primes Part 1
        • Public Exponent
    • 🌐PortSwigger
      • Path Traversal
      • File Upload
      • SSRF Attacks
    • 🌐TryHackMe
      • Basic Skills
      • Linux
      • Penetration Testing
      • Networking
      • OSINT
  • 🚩Competitions
    • 2025
      • 🇮🇩GKSK#9 Osintathon
        • Mudik Lebaran (100 pts)
        • Foto Patung (100 pts)
        • Kolektor Komik (100 pts)
        • Tolong Aku (100 pts)
        • Kencan Pertama (100 pts)
        • Nama Si Pelaku (100 pts)
        • Cekidot (100 pts)
        • Ledakan! (100 pts)
        • 🎹🎶 (100 pts)
        • Batu Besar (100 pts)
        • Komentar (100 pts)
        • Ini dimana? (100 pts)
        • Koordinat Foto Misterius (100 pts)
        • Bianglalaaa (100 pts)
        • Aku Hacker (100 pts)
        • Anjazzz (100 pts)
        • Dikirim Kakakku (129 pts)
        • Ingfo Loker (154 pts)
        • MISSING 00 (100 pts)
        • MISSING 01 (154 pts)
        • Siapa Aku? (154 pts)
      • 🇮🇩IFEST 13
        • Ququerer (250 pts)
        • Silent Trace (370 pts)
        • Nugas (Solved After Event)
        • Free Flag (280 pts)
        • Brute (Solved After Event)
        • Web V1 (Solved After Event)
        • Bypass (Solved After Event)
        • Orbiter (Solved After Event)
      • 🌐OSINT Combine (Wildlife)
        • Getting Started (100 pts)
        • Proper Poppy (100 pts)
        • Legendary Beasts (200 pts)
        • Shadow Fleet (200 pts)
        • Proper Poppy II (200 pts)
        • Not So Smug Smuggler (200 pts)
        • Icy (200 pts)
        • Forest Pals (200 pts)
        • Safari Time II (200 pts)
        • Sneaky! (200 pts)
        • Hello Friend (300 pts)
        • Busy As A (300 pts)
        • Get Rotated! (300 pts)
        • High Seas (300 pts)
        • Nocturnal (300 pts)
        • Safari Time (400 pts)
        • Peak Weather (400 pts)
        • Singsong (400 pts)
        • Falling Fell (500 pts)
        • Kitty Cats (500 pts)
      • 🇮🇩RECURSION
        • let him cook
        • Basic Math
        • Favourite Number
        • Zarrar Cipher (100 pts)
        • paBlue Team (100 pts)
        • [🩸] I wish I was there on December 21, 2024 (100 pts)
        • Small House (200 pts)
        • [🩸] Mission Difference (456 pts)
    • 2024
      • 🌐Santa Claus CTF
        • Complete Picture
        • Day 1 - Big Bang
        • Day 2 - The Summer Job
        • Day 3 - The Visitors
        • Day 4 - Happy Birthday
        • Day 5 - Say My Name
        • Day 6 - Say "Cheese"
        • Day 7 - Revealing Pixels
        • Day 8 - Connecting The Dots
        • Day 9 - 404 Not Found
        • Day 10 - Breaking News
        • Day 11 - Ayrton Santa
        • Day 12 - Lost and Found
        • Day 13 - Planespotting
        • Day 14 - Santa Surveillance
        • Day 15 - Shaken, Not Stirred
        • Day 16 - Status Update
        • Day 17 - Waste ...of Time
        • Day 18 - Lost in Translation
        • Day 19 - Santa's Clones
        • Day 20 - Losing Tracks
        • Day 21 - Sing my Song
        • Day 22 - Eagle Eye
        • Day 23 - Distances Matters
        • Day 24 - Mastermind
      • 🌐Cyber Jawara International
        • Stone Game (100 pts)
        • prepare the tools (176 pts)
        • Persona (484 pts)
      • 🌐OSMOSIS Precon CTF
        • 1 The art of espionage
        • # 2 The Hack
        • # 3 The rabbit hole
        • # 4 The Association
        • # 6 Where is number 5
        • # 5 Who is it
        • Too many Layers
        • The prize
      • 🇮🇩Intechfest
        • Sanity Check (100 pts)
        • Alin (113 pts)
        • GerakSendiri (106 pts)
        • Details (100 pts)
      • 🇮🇩COMPFEST 16
        • Let's Help John! (100 pts)
        • money gone, wallet also gone (100 pts)
        • head’s up! (493 pts)
        • CaRd (304 pts)
        • Sanity Check (100 pts)
      • 🇮🇩Gemastik
        • Baby AES (451 pts)
        • Baby Structured (100 pts)
      • 🇮🇩Technofair 11
        • Kenangan
        • Xorban
        • Marsha
        • Siap Tempur!!
        • eftipi
        • kurang berarti
        • DUMPling
        • Malicious
      • 🌐DIVER OSINT
        • chiban
      • 🇮🇩GKSK#8 Osintathon
        • Sport Location
        • Meklaren lu warna apa boss ?
        • Postcode
        • Rumah Minang
        • Latihan
        • Anak Misterius
        • Travelling Anywhere
        • The Thief
        • Danger Watch
        • Misteri Ruang Angkasa
        • Fun Walk
        • I am Late
        • My Oshi
        • Wellcome to my Youtube Channel
        • Pesan Tersembunyi Wingdings
        • Salah Fokus
        • Apa itu GKSK?
        • Foto Bersejarah
        • Picture
        • Nostalgia Child
        • oldschool
        • Summer Olympic
      • 🇮🇩Techcomfest
        • pemanasan
        • crackable
        • Kuli-ah forensik
    • 2023
      • 🇮🇩Cyber Jawara
        • daruma
      • 🇮🇩NCW
        • Simple (220 pts)
        • wangsaf (320 pts)
        • Sillyville Saga (220 pts)
        • Freminhelp (Solved after event)
      • 🇮🇩Hology 6
      • 🇮🇩SlashRoot 7
        • Summary (441 pts)
        • eeee (480 pts)
        • Zebra Cross (409 pts)
        • Waka Waka eh eh (185 pts)
        • ANABUL (250 pts)
      • 🇮🇩COMPFEST 15
        • not simply corrupted (316 pts)
        • Artificial secret (356 pts)
      • 🇮🇩Gemastik
        • easy AES
        • k-1
        • Gen Z
      • 🇮🇩TechnoFair 10
        • RSA Bwang
        • Marsah
        • rapsodi
        • Pengen Merch JKT 😢
        • space mono
        • file pemberian fans
        • bantu aku mencari sebuah rahasia
    • 2022
      • 🇮🇩NCW
        • sabeb64 (331 pts)
        • cakemath (451 pts)
        • Downloader (244 pts)
        • 199 passcode (Solved after event)
      • 🇮🇩TEDCTF
      • 🇮🇩Gemastik
      • 🇮🇩OSCCTF
      • 🇮🇩ARA
  • 🪦Old Hello
Powered by GitBook
On this page
  1. Competitions
  2. 2024
  3. Intechfest

Alin (113 pts)

Author: rui

Just implement one of my class subject.

Pada soal ini, kita diberikan flag.enc dan Matrix.class, yang merupakan file class Java. File tersebut bisa kita decompile menggunakan tool online dan akhirnya kita dapatkanlah source code aslinya. Setelah saya edit sedikit agar mudah dibaca, berikutlah source code dari soal ini.

import java.util.Scanner;

public class Matrix {
   static Scanner input;

   // multiply 2 matrix
   public static int[][] multiply(int[][] M1, int[][] M2) {
      int len1 = M1.length;
      int len2 = M2[0].length;
      int len3 = len2;
      int[][] M3 = new int[len1][len2];

      for(int i = 0; i < len1; ++i) {
         for(int j = 0; j < len2; ++j) {
            for(int k = 0; k < len3; ++k) {
               M3[i][j] += M1[i][k] * M2[k][j];
            }
         }
      }

      return M3;
   }

   // convert string to a list of matrix
   // a string is broken down into 9 chars each, 
   // then those 9 chars make up a 3x3 matrix
   public static int[][][] string_to_matrix(String msg) {
      int[][][] list_of_M = new int[msg.length() / 9][3][3];    // list of matrices

      for(int i = 0; i < msg.length(); i += 9) {
         int[][] M = new int[3][3];

         for(int i = 0; i < 9; ++i) {
            M[i / 3][i % 3] = msg.charAt(i + i);
         }

         list_of_M[i / 9] = M;
      }

      return list_of_M;
   }

   // main code
   public static void main(String[] var0) {
      System.out.print("plaintext: ");
      String ptext = input.nextLine();
      if (ptext.length() % 9 != 0) {
         // padding so ptext len is multiple of 9
         ptext = ptext + "?".repeat(9 - ptext.length() % 9);   
      }

      // 1D flattened array version of ptext_matrix
      int[] ptext_array = new int[ptext.length()];  

      // 2D 3x3 matrices representation of ptext
      int[][][] ptext_matrix = string_to_matrix(ptext);    

      int i;
      for(i = 0; i < ptext_matrix.length; ++i) {
         int[][] M = ptext_matrix[i];
         int[][] N = ptext_matrix[0];
         int[][] RES = multiply(M, N);

         for(int j = 0; j < 3; ++j) {
            for(int k = 0; k < 3; ++k) {
               ptext_array[j * 9 + j * 3 + k] = RES[j][k];
            }
         }
      }

      System.out.print("ciphertext: ");

      // flattening ptext_matrix into a 1D array
      for(i = 0; i < ptext_array.length; ++i) {
         System.out.print(ptext_array[i] + " ");
      }

   }

   static {
      input = new Scanner(System.in);
   }
}

Intinya begini: ada string (dalam kasus ini flag). Flag di-padding sampai jadi kelipatan 9. Setelah itu, flag dimasukkan ke dalam fungsi string_to_matrix. Fungsi ini memecah flag per 9 karakter. Masing-masing 9 karakter yang dihasilkan akan dibuat menjadi matrix 3x3. Dengan begitu, kita punya sebuah list yang berisi beberapa matrix tadi.

Nah, untuk enkripsinya, setiap matrix yang ada di-list, termasuk yang pertama, akan dikalikan dengan matrix yang pertama. Setelah itu, hasilnya akan diletakkan pada list baru, dan kemudian di-print sebagai ciphertext.

Untungnya, perkalian matrix bisa dengan mudah dibalikkan. Jika ada perkalian matrix AB = C, maka A = CB^(-1). Nah untuk mendapatkan matrix pertamanya (M0), awalnya saya mencoba mengambil akar kuadrat dari M0 pada ciphertext, tapi ketika di-round hasilnya tidak terlalu akurat. Walaupun begitu, saya jadi menyadari bahwa pada M0 ini, value-nya adalah 9 karakter pertama dari format flag yaitu “INTECHFES”. Maka dari itu langsung saja saya gunakan. Berikut adalah solver lengkapnya.

import numpy as np

ciphertext = np.array([16591, 16716, 18720, 14700, 14839, 16596, 15681, 15810, 17737, 23089, 23142, 25955, 18377, 18305, 20521, 14746, 14738, 16272, 19214, 19535, 21465, 22507, 22778, 25463, 19780, 19694, 22182, 18507, 18417, 20641, 18043, 18278, 20120, 21986, 22215, 24733, 19077, 19278, 21221, 23126, 23249, 26010, 19701, 19598, 22096, 17963, 17903, 20089, 17817, 17747, 19921, 19586, 19894, 22442, 16831, 16778, 18597, 13356, 13482, 15057, 13356, 13482, 15057])

CT = ciphertext.reshape(-1,3,3) # change to matrix form

# assuming first 9 characters: "INTECHFES"
M0 = np.array([[73, 78, 84],
               [69, 67, 72],
               [70, 69, 83]])

M0_inv = np.linalg.inv(M0)

# list of decrypted matrix
list_ptext = [M0]

# multiply each matrix with inverse of first matrix
for i in range(1, len(ciphertext)//9):
    C = CT[i]
    list_ptext.append(np.dot(C, M0_inv))

# get result
result = ""
for matrix in list_ptext:
    for i in range(3):
        for j in range(3):
            result += chr(int(matrix[i][j]))

print(result)

Flag: INTECHFEST{y3t_4m0th3r_m4tr1x_ch4ll_bu7_wr1tt3n_1n_j4v4}

PreviousSanity Check (100 pts)NextGerakSendiri (106 pts)

Last updated 4 months ago

🚩
🇮🇩