Bird
0
0

Given the following Python snippet analyzing a disk image file:

medium📝 Analysis Q13 of 15
Cybersecurity - Digital Forensics
Given the following Python snippet analyzing a disk image file:
with open('disk.img', 'rb') as f:
    data = f.read(512)
print(len(data))

What will be the output?
A512
B0
CAn error because 'rb' mode is invalid
DThe entire disk image size
Step-by-Step Solution
Solution:
  1. Step 1: Understand file reading mode

    Opening with 'rb' means read binary mode, which allows reading raw bytes from the file.
  2. Step 2: Read 512 bytes and check length

    The code reads 512 bytes from the start of the file, so len(data) will be 512 if the file is at least that big.
  3. Final Answer:

    512 -> Option A
  4. Quick Check:

    Read 512 bytes = length 512 [OK]
Quick Trick: Read bytes length matches requested size if file is large enough [OK]
Common Mistakes:
MISTAKES
  • Thinking 'rb' is invalid mode
  • Assuming entire file is read
  • Expecting zero length if file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cybersecurity Quizzes