Animație de „alunecare de teren”
În caz că 2 puncte alăturate din harta de înălțime au o diferență de înălțime d mai mare de un prag , se va face un „transfer” de înălțime ε de la punctul cu înalțime mai mare la celălalt. Acest lucru se repetă în fiecare cadru până când d este sub prag:
Valoarea ε utilizată în procesul de „transfer” de înălțime trebuie să țină cont de timpul ultimului cadru, respectiv de valoarea deltaTime.
Valoarea pragului trebuie să fie aleasă astfel încât animația de „alunecare de teren” să fie realizată de-a lungul mai multor cadre. Altfel spus, animația trebuie să se poată observa vizual și nu trebuie să se realizeze instant, deoarece nu s-ar mai numi o animație.Implementeaza alunecarea de teren
#include "lab_m1/tema1/tema1.h"
#include "lab_m1/tema1/transform2D.h"
#include "lab_m1/lab3/object2D.h"
I need to find a flag.Here are some tips on how to find it.# Encrypted
It's all part of the dance, where secret messages hide, XORs twirl, and
randomness is the masquerade ball.
Try your own luck at:
isc2024.1337.cx:11154.
Hints:
you either have a very powerful PC, or write optimized C / Rust / whatever
(even Haskell is faster! ;) )
if it takes more than 15 mins, you're doing smth wrong...
and PLEASE do NOT hammer (DoS) the server... it is sufficient to only issue
the request ONCE! Here is a code in python that is given #!/usr/bin/python3
import math
import base64
import random
def xor(a, b):
return bytes([x ^ y for x, y in zip(a, b)])
class LCG:
def init(self, a, b):
self.a = a
self.b = b
self.mod = 2 ** 16
self.state = 0
if name == 'main':
flag = "This_Is_NOT_SpeishFlag{asdfg_not_that_easy}"
plaintext = "Stay your hand! Gotcha!\n" +
"You do not know this part, \n" +
"but it ends with a\n" + flag
# note: message is always ASCII!
bintext = plaintext.encode("ASCII")
Assistant
User
i run the python script and there was no output displayed.
Assistant
User
i dont know wich is the base64 encoded ciphertext
Assistant
The base64 encoded ciphertext should have been printed when the program ran, so it seems you might need to recreate the initial portion to examine the output. Based on the script you provided, the base64 encoded ciphertext is output at the end of the main section. Try this:
Run the Encryption Script: Use the initial provided script (after understanding and adapting it for encryption), and it should output the base64 encoded ciphertext.
User
it took more that 15 minutes and i stop the rule.# Encrypted
It's all part of the dance, where secret messages hide, XORs twirl, and
randomness is the masquerade ball.
Try your own luck at:
isc2024.1337.cx:11154.
Hints:
you either have a very powerful PC, or write optimized C / Rust / whatever
(even Haskell is faster! ;) )
if it takes more than 15 mins, you're doing smth wrong...
and PLEASE do NOT hammer (DoS) the server... it is sufficient to only issue
the request ONCE!
Assistant
}
void Tema1::RenderTank(float x, float y, float rotationAngle, float turretAngle, int tank) {
glm::mat3 modelMatrix;
}
std::vectorglm::vec2 CalculateProjectilePath(glm::vec2 startPosition, float angle, float initialSpeed, float gravity, int numSegments) {
std::vectorglm::vec2 trajectory;
float timeStep = 0.1f; // Intervalul de timp dintre fiecare punct
for (int i = 0; i < numSegments; i++) {
float t = i * timeStep;
float x = startPosition.x + initialSpeed * cos(angle) * t;
float y = startPosition.y + initialSpeed * sin(angle) * t - 0.5f * gravity * t * t;
trajectory.push_back(glm::vec2(x, y));
if (y < 0) {
break;
}
}
return trajectory;
void Tema1::OnMouseMove(int mouseX, int mouseY, int deltaX, int deltaY)
{
// Add mouse move event
}
void Tema1::OnMouseBtnPress(int mouseX, int mouseY, int button, int mods)
{
// Add mouse button press event
}
void Tema1::OnMouseBtnRelease(int mouseX, int mouseY, int button, int mods)
{
// Add mouse button release event
}
void Tema1::OnMouseScroll(int mouseX, int mouseY, int offsetX, int offsetY)
{
}
void Tema1::OnWindowResize(int width, int height)
{
}
Implementarea animației de „alunecare de teren” în contextul jocului descris presupune modificarea terenului pe baza diferențelor de înălțime dintre punctele adiacente și vizualizarea acestei modificări sub forma unei animații de-a lungul timpului.
Aici este planul de implementare:
Definirea Valorii Pragului și Transferului:
Se definește un prag threshold care specifică diferența maximă permisă între două puncte adiacente înainte de a avea loc o alunecare.
Se definește valoarea eps pentru ajustarea înălțimii într-un singur pas al animației.
Aceste valori pot fi ajustate pentru a obține o animație mai lentă sau mai rapidă.
Funcția de Alunecare:
Parcurgem toate punctele adiacente din lista terrain_points.
Calculăm diferența de înălțime d dintre fiecare două puncte adiacente.
Dacă d depășește threshold, efectuăm un transfer lent al înălțimii folosind eps și deltaTime pentru a asigura o animație vizibilă.
Actualizarea Animației în Loop-ul Update:
Integram funcția de alunecare în funcția Update pentru a fi apelată în fiecare cadru.
Iată un exemplu simplu de cod de implementare pentru animație de alunecare de teren:
void Tema1::SlideTerrain(float deltaTimeSeconds) {
float threshold = 15.0f; // Pragul pentru diferența de înălțime
float eps = 0.1f; // Cantitatea transferată de înălțime pentru fiecare pas
for (size_t i = 1; i < terrain_points.size(); ++i) {
glm::vec2& p1 = terrain_points[i - 1];
glm::vec2& p2 = terrain_points[i];
float heightDiff = p1.y - p2.y;
if (fabs(heightDiff) > threshold) {
// Aplică transferul de înălțime
float transfer = eps * deltaTimeSeconds;
if (heightDiff > 0) {
// p1 mai sus decât p2, alunecați în jos
p1.y -= transfer;
p2.y += transfer;
} else {
// p2 mai sus decât p1, alunecați în jos
p1.y += transfer;
p2.y -= transfer;
}
}
}
}
void Tema1::Update(float deltaTimeSeconds) {
glm::ivec2 resolution = window->GetResolution();
// Actualizează terenul cu animația de alunecare de teren
SlideTerrain(deltaTimeSeconds);
// ... codul existent pentru actualizarea și redarea scenei ...
}
Cu acest mecanism, punctele de pe hartă vor ajusta înălțimea lor treptat de-a lungul mai multor cadre, creând efectul dorit de alunecare. Ajustați valorile threshold și eps pentru a se potrivi stilului și dinamismului jocului dumneavoastră.
params = [random.randint(1337, 10000) for _ in (1, 2)]
lcg = LCG(*params)
states = [lcg.next() for _ in range(math.ceil(len(bintext) / 2))]
key = b"".join([state.to_bytes(2, "little") for state in states])
ciphertext = xor(bintext, key)
print(base64.b64encode(ciphertext).decode("ASCII"))
The challenge you provided involves breaking an encryption that uses a Linear Congruential Generator (LCG) for generating key material and then XORing it with an ASCII plaintext message. Here's a high-level approach on how you might go about breaking the encryption to retrieve the flag:
Understanding the Encryption
XOR Encryption: The message is XORed with key material generated by the LCG. If you can reconstruct the key, you can decrypt the message.
LCG Predictability: The LCG is defined by the parameters (a) and (b), and it updates the state using a formula. If (a) and (b) can be determined or guessed, the sequence generated by the LCG can be predicted.
Solving Steps
Capture Parameters: We know that the seed is set to 0 (self.state = 0). Thus, the first LCG-generated number directly gives you (b), because (state = (a \times 0 + b) % mod = b).
Parameter Range: The parameters are randomly picked between 1337 and 10000. This range is limited enough to apply a brute-force or optimized search to determine possible pairs of ((a, b)).
Decrypt with Known Plaintext: Part of the plaintext is known ("Stay your hand! Gotcha!\nYou do not know this part, \n"). Use this to potentially validate guesses for ((a, b)) by attempting to reconstruct the stream and decrypt sections of the ciphertext.
Implementation Strategy
An efficient way to try to decrypt the message could be:
Based on the fact that the initial state is known and the first generated value gives us (b), run over the range of possible (a) values.
Generate the key stream using ((a, b)) pairs and try to decrypt the message.
Verify the beginning of the decrypted message against the known plaintext portion to validate the guess.
Once the correct ((a, b)) pair is found, continue decrypting to recover the full message and flag.
Here's a Python script outline for how to approach finding the flag:
import base64
def xor(a, b):
return bytes([x ^ y for x, y in zip(a, b)])
class LCG:
def __init__(self, a, b):
self.a = a
self.b = b
self.mod = 2 ** 16
self.state = 0
def next(self):
self.state = (self.a * self.state + self.b) % self.mod
return self.state
def decrypt(ciphertext, a, b, length):
lcg = LCG(a, b)
states = [lcg.next() for _ in range(length // 2)] # since each key unit is 2 bytes
key = b"".join([state.to_bytes(2, "little") for state in states])
return xor(ciphertext, key)
# The given base64 encoded ciphertext
ciphertext_encoded = "..." # replace with the actual base64-encoded ciphertext
ciphertext = base64.b64decode(ciphertext_encoded)
known_plaintext_start = b"Stay your hand! Gotcha!\nYou do not know this part, \n"
# Known parameter range
param_min, param_max = 1337, 10000
for a in range(param_min, param_max + 1):
for b in range(param_min, param_max + 1):
decrypted = decrypt(ciphertext, a, b, len(ciphertext))
if decrypted.startswith(known_plaintext_start):
print("Decryption successful with a =", a, "b =", b)
print(decrypted.decode('ascii'))
break
This script iterates over the possible values for (a) and uses the first LCG state for (b), attempting to decrypt the message with each ((a, b)) pair. It checks if the decrypted message begins with the known plaintext segment to identify a valid decryption. Once you find a working pair, it should reveal the full plaintext including the flag.
If you ran the Python script and no output was displayed, there are a few things to check and debug. Here's how you can troubleshoot the issue:
Verify the Ciphertext: Ensure that you have replaced the placeholder "..." with the actual base64-encoded ciphertext from your problem description.
Check the Known Plaintext: Double-check that the known plaintext segment ("Stay your hand! Gotcha!\nYou do not know this part, \n") is correct and matches the expected start of the decrypted message.
Debug the LCG: Print some initial parameters and intermediary values to verify the logic.
Print Progress: Add print statements to track progress and see if the script is running as expected.
Here’s a modified version of the script with added debug print statements to help you identify where the issue might be:
import base64
import itertools
def xor(a, b):
return bytes([x ^ y for x, y in zip(a, b)])
class LCG:
def __init__(self, a, b):
self.a = a
self.b = b
self.mod = 2 ** 16
self.state = 0
def next(self):
self.state = (self.a * self.state + self.b) % self.mod
return self.state
def decrypt(ciphertext, a, b, length):
lcg = LCG(a, b)
states = [lcg.next() for _ in range(length // 2)]
key = b"".join([state.to_bytes(2, "little") for state in states])
return xor(ciphertext, key)
# Replace with the actual base64-encoded ciphertext from your problem description
ciphertext_encoded = "PLACE_YOUR_BASE64_ENCODED_CIPHERTEXT_HERE"
ciphertext = base64.b64decode(ciphertext_encoded)
known_plaintext_start = b"Stay your hand! Gotcha!\nYou do not know this part, \n"
param_min, param_max = 1337, 10000
found = False
for a, b in itertools.product(range(param_min, param_max + 1), repeat=2):
decrypted = decrypt(ciphertext, a, b, len(ciphertext))
if decrypted.startswith(known_plaintext_start):
print("Decryption successful with a =", a, "b =", b)
print(decrypted.decode('ascii'))
found = True
break
if not found:
print("No valid decryption found. Please recheck your inputs.")
Next Steps:
Replace Ciphertext: Make sure you accurately copy the relevant base64-encoded ciphertext you obtained.
Execution Time: While trying a large number of parameters can take some time, the solution should still be efficient. If your loop is taking too long, consider checking your system's computational resources or adjusting efficiency by seeking patterns in initial conditions.
Verbose Output: If needed, print additional details (e.g., parameter values or partial decryptions) to help identify if the script is progressing properly.
import math
import base64
import random
def xor(a, b):
return bytes([x ^ y for x, y in zip(a, b)])
class LCG:
def __init__(self, a, b):
self.a = a
self.b = b
self.mod = 2 ** 16
self.state = 0
def next(self):
self.state = (self.a * self.state + self.b) % self.mod
return self.state
if __name__ == '__main__':
flag = "This_Is_NOT_SpeishFlag{asdfg_not_that_easy}"
plaintext = "Stay your hand! Gotcha!\n" + \
"You do not know this part, \n" + \
"but it ends with a\n" + flag
bintext = plaintext.encode("ASCII")
params = [random.randint(1337, 10000) for _ in (1, 2)]
lcg = LCG(*params)
states = [lcg.next() for _ in range(math.ceil(len(bintext) / 2))]
key = b"".join([state.to_bytes(2, "little") for state in states])
ciphertext = xor(bintext, key)
encoded_ciphertext = base64.b64encode(ciphertext).decode("ASCII")
print("Base64 Encoded Ciphertext: ", encoded_ciphertext)
This script will output a "Base64 Encoded Ciphertext". Once you get this output, you use it as your encoded ciphertext input in the decryption script example I provided earlier.
Important:
Randomness: Each time you run the above encryption script, it will give a different output because of the use of random.randint. For purposes of testing, you might want to fix the seed.
Real Scenario: In a practical scenario, you'd capture this output from the challenge environment, e.g., by interacting with a challenge server. If this is for a challenge or CTF (Capture The Flag), the server would typically provide this to you directly.
Given the constraints and hints provided, it sounds like the challenge is designed to be solvable within a short amount of time using an optimized approach or by leveraging available insights more efficiently. Here’s a more structured approach to what you might be facing:
Key Steps:
Single Request and Get Output: If the problem is served via a network challenge (as indicated by the server address), ensure you’re only interacting with it once, grabbing the necessary output (presumably the ciphertext) and any additional clues or data.
Understand the Constraints: The problem gives strong hints regarding performance optimization:
Mathematical Insight: The linear congruential generator (LCG) is the crux here. Knowing ( b ) from the first generated value could lead to potential patterns or direct computation paths.
Opt for Performance: Use Python for logic but consider implementing the intensive loops in a compiled, efficient language like C or Rust.
Reduce the Search Space: If the attempt is taking too long:
Inspect bounds and conditions — it might not actually be necessary to brute force all pairs of ( (a, b) ) due to bounds issues.
Find shortcuts or relationships that aid rapid verification of candidate solutions.
Network Interaction: If the task involves communicating with an external service, ensure:
Your script only performs essential network operations once.
Any attempts to brute force or otherwise stress the server should be avoided.
Efficient Language Use: If Python proves inefficient for this load, re-implement parts critical to computation in a faster language.
Here’s how you might proceed given constraints:
Optimizing and Implementing:
Keep only required portions in Python for clarity, translating critical performance paths to C/Rust where feasible.
Performance Path Example (Python + C/Rust Hybrid Outline):
Here’s a simple outline that demonstrates the interoperability idea:
Python Script (Calling C/Rust for Compute-Heavy Operations):
import ctypes
# Load your compiled C/Rust library
my_lib = ctypes.CDLL('./path_to_compiled_library.so')
# Define call spec if necessary (e.g., my_lib.try_decrypt.argtypes = [<arg types>])
def try_decrypt(ciphertext, known_plaintext):
# Call an optimized routine for decryption attempts
return my_lib.try_decrypt(ciphertext, known_plaintext) # Placeholder
# Rest of the script utilizing try_decrypt function
C/Rust Code (Optimized Logical Loop):
Here you write the actual decryption logic with intense computation in C or Rust to run over potential LCG parameters quickly, compiled to a shared object/DLL to call from Python.
Tips for Efficient Testing:
Focus on Constraints and Logic: Verify any loopholes in initial constraints, headers hint explicitly at using logical reasoning besides compute optimization.
Research LCG Characteristics: Sometimes, mathematical properties/prior solutions regarding LCG can offer insights for optimizations.
Use Debugging Outputs: Isolate potential areas where excessive computation could arise, using debugging to curtail redundant path explorations.
Finally, with a focused approach based on insights provided, achieving a fast solution should be feasible without exhaustive searches.