COMP1521 24T1 — Assignment 2 a file archiver

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
.trats ot ecalp lufesu a eb ot oediv weivrevo tnemngissa eht dnif yam uoY
;)2 tesbus( selif fo tsil a morf yxalag a etaerc
;)1 tesbus( yxalag a morf detcartxe selif fo snoissimrep elif eht tes
;)1 tesbus( ;sehsah rats gnikcehc yb ,ytirgetni rof yxalag a kcehc
;)1 tesbus( yxalag a morf selif tcartxe
;)0 tesbus( rebmun cigam rats eht kcehc
;)0 tesbus( yxalag a ni selif fo )setyb fo rebmun( ezis eht tsil
;)0 tesbus( yxalag a ni tcejbo hcae fo snoissimrep eht tsil
;)0 tesbus( yxalag a ni tcejbo hcae fo seman htap eht tsil
nac ecaps fo noitatnemelpmi etelpmoc A
liated erom ni debircsed si tamrof sihT ;tcejbo metsys elif eno sdrocer rats a erehw ;srats erom ro eno fo pu edam si tamrof yxalag ehT
.tamrof yxalag eht rof revihcra elif a ,ecaps gnitnemelpmi eb lliw uoy ,tnemngissa siht nI
.erolpxe ot eloh-tibbar suollevram a si stamrof evihcra
fo tsil s’aidepikiW .nommoc si piZ ,swodniW no saerehw ;nommoc si rat ,smetsys ekil-xin* no :stamrof evihcra fo rebmun tsav a era erehT
.srevihcra elif sa eseht
etalupinam ro etaerc nac taht sloot ot refer netfo eW .tneiciffe erom noisserpmoc ekam netfo nac dna ,tneinevnoc erom selif fo tropsnart
d n a p u k c a b e k a m n a c e s e h T . s e l i f e l p i t l u m f o a t a d a t e m r e h t o d n a s e m a n , s t n e t n o c e h t n i a t n o c n a c h c i h w e l i f e l g n i s ak s is ea v i hT c r ae e l ih f T A
atad yranib no snoitarepo tuptuo-tupni gnidulcni ,snoitarepo elif gnidnatsrednu
;gnildnah rorre tsubor dna snoitarepo level-etyb gnidulcni ,C gnisitcarp
;stcejbo metsys elif fo gnidnatsrednu etercnoc a gnidlisubmiA
goL egnahC
snoitidnoC tnemngissA
kroW fo snoisreV etaidemretnI
emehcS tnemssessA
noissimbuS
tnemssessA
snoitacifiralC dna snoitpmussA
hsah rats ehT
tamrof rats dna yxalag ehT
noitatnemelpmi ecnerefeR
srorrE gnildnaH
detratS gnitteG
revihcra elif a :2 tnemngissA

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
$ mkdir -m 700 space $ cd space
$ 1521 fetch space
space_main.c
space_hash.c
space_6_bit.c
dcc -c -o space.o space.c
dcc -c -o space_main.o space_main.c
dcc -c -o space_hash.o space_hash.c
dcc -c -o space_6_bit.o space_6_bit.c
dcc space.o space_main.o space_hash.o space_6_bit.o -o space $ ./space -l a.galaxy
list_galaxy called to list galaxy: ‘a.galaxy’
$ dcc space.c space_main.c space_hash.c space_6_bit.c -o space $ ./space -C b.galaxy
check_galaxy called to check galaxy: ‘a.galaxy’
$ unzip examples.zip
:elpmaxe roF
.yxalag a ni seirotcerid/selif eht fo seman htap eht tnirp dluohs ecaps ,tnemugra enil-dnammoc eht neviG
yxalag a fo stnetnoc eht fo tsil a tnirP :0 tesbuS
.yxalag a fo stnetnoc eht fo tsil deliated a tnirp
dna ,yxalag a fo stnetnoc eht fo tsil a tnirp
nac taht edoc tnemelpmi ot deen uoy ,0 tesbus etelpmoc oT
.tsniaga margorp ruoy tset ot selif yxalag. fo lluf dellac yrotcerid a teg ot piznu nur dluohs uoY
.selif ro artxe etaerc yllanoitpo yam uoY
:siht ekil elipmoc nac uoy elbaliava ekam evah t’nod uoy fI
.tluser eht nur ot elba eb dluohs uoy dna ;edoc dedivorp eht elipmoc ot ekam nur nac uoY
.ecaps rof tnemgarf elifekaM a sniatnoc
.elif siht egnahc ton oD .3 tesbus rof tamrof
tib-6 eht tnemelpmi ot eseht llac dluohs uoY .snoitcnuf tib_6_morf_rats dna tib_6_ot_rats eht sniatnoc
.elif siht egnahc
ton oD .1 tesbus rof sehsah etaluclac ot noitcnuf siht llac dluohs uoy ;noitcnuf hsah_rats eht sniatnoc
.elif siht egnahc ton oD .snoitinifed tnatsnoc lufesu emos dna snoitaralced noitcnuf derahs sniatnoc
.elif siht egnahc ton oD .ecaps ot nevig
stnemugra enil dnammoc eht no gnidneped ,yxalag_kcehc ro ,yxalag_etaerc ,yxalag_tcartxe ,yxalag_tsil
fo eno sllac neht hcihw dna ,stnemugra enil dnammoc eht esrap ot edoc sah hcihw ,niam a sniatnoc
.elif siht ot snoitcnuf nwo ruoy dda osla nac uoY .tnemngissa
eht etelpmoc ot edoc dda ot deen uoy hcihw ot ,yxalag_etaerc dna ,yxalag_tcartxe ,yxalag_kcehc
,yxalag_tsil ,snoitcnuf ruof fo snoitinifed laitrap sniatnoc ti :egnahc ot deen uoy elif ylno eht si
:selif gniwollof eht uoy evig lliw sihT
.elif rat a ro elif piz a sa selif dedivorp eht daolnwod nac uoy ,ESC ta gnikrow ton er’uoy fI
gninnur yb edoc dedivorp eht hctef dna ,yrotcerid siht ot egnahc ,tnemngissa siht rof yrotcerid wen a etaerC
detratS gnitteG
.)3 tesbus( stamrof tib-6 dna tib-7 ni seixalag etaerc dna ,tcartxe
dna ;)3 tesbus( seirotcerid edulcni taht seixalag etaerc dna ,tcartxe ,tsil

2024/3/29 09:43
COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
# List each item in the galaxy called text_file.galaxy, which is in the examples directory $ ./space -l examples/text_file.galaxy
# List each item in the galaxy called 4_files.galaxy, which is in the examples directory $ ./space -l examples/4_files.galaxy
last_goodbye.txt
these_days.txt
# List each item in the galaxy called hello_world.galaxy, which is in the examples directory $ ./space -l examples/hello_world.galaxy
hello.java
$ ./space -L examples/text_file.galaxy
-rw-r–r– 8 56 hello.txt
# List the details of each item in the galaxy called 4_files.galaxy, which is in the examples directory
$ ./space -L examples/4_files.galaxy
-rw-r–r– 8 256 256.bin
-rw-r–r– 8 56 hello.txt
-r–r–r– 8 166 last_goodbye.txt
-r–rw-r– 8 148 these_days.txt
# List the details of each item in the galaxy called hello_world.galaxy, which is in the examples directory $ ./space -L examples/hello_world.galaxy
-rw-r–r– 8
-rw-r–r– 8
-rw-r–r– 8
-rw-r–r– 8
-rw-r–r– 8
-rw-r–r– 8 117 hello.java
-rw-r–r– 8 30 hello.js
-rwxr-xr-x 8 47 hello.pl
-rwxr-xr-x 8 103 hello.py
-rw-r–r– 8 45 hello.rs
-rw-r–r– 8 123 hello.s
-rwxr-xr-x 8 41 hello.sh
-rw-r–r– 8 24 hello.sql
93 hello.c
82 hello.cpp
65 hello.d
77 hello.go
32 hello.hs
space_main.c
print_bytes.c
.enil dnammoc eht no deificeps era snoitpo
ro eht fo rehtie nehw
ni yxalag_tsil noitcnuf eht sllac
.bal 8 keew ruo morf weiveR
.edoc detaeper diova ot tcurtsnoc nac uoy snoitcnuf eht tuoba ylluferac knihT
.sregetni otni setyb enibmoc ot dna sa hcus snoitarepo esiwtib C esU
woleb noitacificeps tamrof rats eht dnatsrednu uoy erus ekaM
.setyb daer ot ctegf esU
.elif yxalag eht nepo ot nepof esU
. ni yxalag_tsil ot edoc ddA
.eman htap yrotcerid/elif eht .
dna ,setyb ni ezis yrotcerid/elif eht .
,)tluafed eht( 8 ro 7 ,6 fo eno eb lliw hcihw tamrof rats eht .
,snoissimrep yrotcerid/elif eht .
:tnirp ,yxalag deificeps eht ni elif hcae rof ,dluohs ecaps ,tnemugra enil-dnammoc eht neviG
yxalag a fo stnetnoc eht fo tsil deliated a tnirP :0 tesbuS
Code Help, Add WeChat: cstutorcs
2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
ctegf dna pool a esu osla nac uoy tub ,elif yxalag eht fo strap revo piks ot desu eb nac keesf
.ezis elif eht tnirp ot ekil tamrof a esu :tniH
.ecneinevnoc a sa ylerup selif elpmaxe dedivorp eht htiw enod neeb sah sihT .yxalag. htiw dne ylirassecen ton od selif yxalag
.yxalag eht ni raeppa yeht redro eht si selif tsil uoy redro ehT
# Check the galaxy called 4_files.galaxy, which is in the examples directory $ ./space -C examples/4_files.galaxy
256.bin – correct hash
hello.txt – correct hash
last_goodbye.txt – correct hash
these_days.txt – correct hash
# Check the galaxy called examples/hello_world.bad_hash.galaxy, which is in the examples directory $ ./space -C examples/hello_world.bad_hash.galaxy
hello.c – correct hash
hello.cpp – correct hash
hello.d – correct hash
hello.go – correct hash
hello.hs – correct hash
hello.java – correct hash
hello.js – correct hash
hello.pl – correct hash
hello.py – correct hash
hello.rs – correct hash
hello.s – correct hash
hello.sh – correct hash
hello.sql – incorrect hash 0x19 should be 0x43
# Check the galaxy called text_file.bad_magic.galaxy, which is in the examples directory $ ./space -C examples/text_file.bad_magic.galaxy
error: incorrect first star byte: 0x39 should be 0x63
space_main.c space.c check_galaxy space.c
.etadpu nac ti hcihw eulav hsah a ot retniop a ekat noitcnuf eht evah :tniH .htob seod taht
noitcnuf a etirw os ,eulav hsah wen a etaluclac ot llac ot deen uoy htiw daer uoy etyb yreve rof ,elpmaxe roF
.edoc detaeper diova ot tcurtsnoc nac uoy snoitcnuf eht tuoba ylluferac knihT
.seulav hsah etaluclac ot llaC
. ni ot edoc ddA
.enil dnammoc eht no deificeps si noitpo eht nehw ni yxalag_kcehc noitcnuf eht sllac
.yxalag eht ni deificeps snoissimrep eht ot selif detcartxe rof snoissimrep elif tes dluohs tI
.yxalag deificeps eht ni selif eht tcartxe dluohs ecaps ,tnemugra enil-dnammoc eht neviG
yxalag a morf selif tcartxE :1 tesbuS
.tcerrocni si ti fi rorre na time dna ,rats hcae fo )etyb tsrif( rebmun cigam rats eht kcehc osla dluohs tI
:elpmaxe roF .yxalag deificeps eht ni sehsah eht kcehc dluohs ecaps ,tnemugra enil-dnammoc eht neviG
yxalag a fo stnetnoc eht kcehC :1 tesbuS
.yxalag a morf selif tcartxe
dna ,yxalag a fo stnetnoc eht kcehc
nac taht edoc tnemelpmi ot deen uoy ,1 tesbus etelpmoc oT

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
# space will extract files into the current working directory.
# So as not to clutter your assignment directory, you should create a # temporary directory, ‘tmp’, and change to it. Once in that directory, # both your space program and ‘examples/’ will be in its parent
# directory — hence the use of ‘..’ in these path names.
# Make a directory called tmp. $ mkdir -p tmp/
# Change into the tmp directory. $ cd tmp/
# Forcibly remove all files inside the tmp directory.
$ rm -f * .*
# Use your program to extract the contents of text_file.galaxy.
$ ../space -x ../examples/text_file.galaxy
Extracting: hello.txt
# Show the contents of hello.txt in the terminal.
# You can manually open it in your text editor too, if you like.
$ cat hello.txt
Hello COMP1521
I hope you are enjoying this assignment.
# Forcibly remove all files inside the tmp directory.
$ rm -f * .*
# Use your program to extract the contents of hello_world.galaxy.
$ ../space -x ../examples/hello_world.galaxy
Extracting: hello.c
Extracting: hello.cpp
Extracting: hello.d
Extracting: hello.go
Extracting: hello.hs
Extracting: hello.java
Extracting: hello.js
Extracting: hello.pl
Extracting: hello.py
Extracting: hello.rs
Extracting: hello.s
Extracting: hello.sh
Extracting: hello.sql
# Show the first 25 lines from the extracted files to confirm the extraction was successful. $ cat $(echo * | sort) | head -n 25
extern int puts(const char *s);
int main(void)
puts(“Hello, World!”);
return 0; }
#include
int main () {
std::cout << "Hello, world!" << std::endl; import std.stdio; void main() { writeln("Hello, world!"); package main import "fmt" func main() { fmt.Println("Hello, World!") main = putStrLn "Hello, World!" # Forcibly remove all files inside the tmp directory $ rm -f * .* # Use your program to extract the contents of meta.galaxy. $ ../space -x ../examples/meta.galaxy Extracting: 1_file.subdirectory.7-bit.galaxy Extracting: 1_file.subdirectory.galaxy Extracting: 2_files.7-bit.galaxy https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html 5/17 2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver Extracting: 2_files.galaxy Extracting: 3_files.7-bit.galaxy Extracting: 3_files.bad_hash.galaxy Extracting: 3_files.bad_magic.galaxy Extracting: 3_files.galaxy Extracting: 3_files.subdirectory.7-bit.galaxy Extracting: 3_files.subdirectory.bad_hash.galaxy Extracting: 3_files.subdirectory.bad_magic.galaxy Extracting: 3_files.subdirectory.galaxy Extracting: 4_files.galaxy Extracting: all_the_modes.subdirectory.7-bit.galaxy Extracting: all_the_modes.subdirectory.galaxy Extracting: all_three_formats.6-bit.galaxy Extracting: binary_file.galaxy Extracting: hello_world.7-bit.galaxy Extracting: hello_world.bad_hash.galaxy Extracting: hello_world.bad_magic.galaxy Extracting: hello_world.galaxy Extracting: lecture_code.subdirectory.7-bit.galaxy Extracting: lecture_code.subdirectory.galaxy Extracting: small.6-bit.galaxy Extracting: small.7-bit.galaxy Extracting: small.galaxy Extracting: text_file.7-bit.galaxy Extracting: text_file.bad_hash.galaxy Extracting: text_file.bad_magic.galaxy Extracting: text_file.galaxy Extracting: tiny.6-bit.galaxy Extracting: tiny.7-bit.galaxy Extracting: tiny.galaxy # Show the first 10 items in this directory alphabetically to check extraction was successful. $ ls -1 $(echo * | sort) | head 1_file.subdirectory.galaxy 1_file.subdirectory.compressed.galaxy 2_files.galaxy 2_files.compressed.galaxy 3_files.bad_hash.galaxy 3_files.bad_magic.galaxy 3_files.galaxy 3_files.compressed.galaxy 3_files.subdirectory.bad_hash.galaxy 3_files.subdirectory.bad_magic.galaxy # Go back into the directory with your code. # Remove the tmp directory and everything inside it. $ rm -rf tmp/ https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html 6/17 space_main.c .elpmaxe c.domhc eht ni elif a fo snoissimrep eht gnittes dna elpmaxe c.ctegf_pc eht ni elif a ot setyb gniypoc derevoc ew selif no serutcel ruo nI .elif hcae ot setyb etirw ot ctupf esU .gnitcartxe era uoy elif hcae nepo ot nepof esU . ni yxalag_tcartxe ot edoc ddA .enil dnammoc eht no deificeps si noitpo eht nehw ni yxalag_tcartxe noitcnuf eht sllac .rorre na fo tneve eht ni selif detcartxe yllaitrap/detcartxe ydaerla evael nac ecaps .tsixe ydaerla taht selif na etirwrevo dluohs ecaps .selif fo tsil a morf yxalag a etaerc nac taht edoc tnemelpmi ot deen uoy ,2 tesbus etelpmoc oT 2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html # These "echo" lines show you how to create these test files and what their contents are. # Create a file called hello.txt with the contents "hello". $ echo hello >hello.txt
# Create a file called hola.txt with the contents “hola”. $ echo hola >hola.txt
# Create a file called hi.txt with the contents “hi”.
$ echo hi >hi.txt
# Set the permissions of these files to 644 (octal permission string (equivalent to rw-r–r–)). # When you list the contents of the galaxy, the permissions should match this.
$ chmod 644 hello.txt hola.txt hi.txt
# Create a galaxy called selamat.galaxy with the files hello.txt, hola.txt, and hi.txt.
$ ./space -c selamat.galaxy hello.txt hola.txt hi.txt
Adding: hello.txt
Adding: hola.txt
Adding: hi.txt
# List the contents of selamat.galaxy.
$ ./space -L selamat.galaxy
-rw-r–r– 8 6 hello.txt
-rw-r–r– 8 5 hola.txt
-rw-r–r– 8 3 hi.txt
# Make a directory called tmp.
$ mkdir -p tmp/
# Change into the tmp directory.
# Forcibly remove all files inside the tmp directory.
$ rm -f * .*
# Use your program to extract the contents of selamat.galaxy.
$ ../space -x ../selamat.galaxy
Extracting: hello.txt
Extracting: hola.txt
Extracting: hi.txt
# Check that the extracted file hello.txt is the same as the source file ../hello.txt.
$ diff -s ../hello.txt hello.txt
Files ../hello.txt and hello.txt are identical
# Check that the extracted file hola.txt is the same as the source file ../hola.txt.
$ diff -s ../hola.txt hola.txt
Files ../hola.txt and hola.txt are identical
# Check that the extracted file hi.txt is the same as the source file ../hi.txt.
$ diff -s ../hi.txt hi.txt
Files ../hi.txt and hi.txt are identical
# Go back into the directory with your code.
# Remove the tmp directory and everything inside it.
$ rm -rf tmp/
$ ./space -a bonjour.galaxy hello.txt Adding: hello.txt
$ ./space -L bonjour.galaxy -rw-r–r– 8 6 hello.txt
$ ./space -a bonjour.galaxy hola.txt hi.txt Adding: hola.txt
Adding: hi.txt
$ ./space -L bonjour.galaxy
-rw-r–r– 8
-rw-r–r– 8
-rw-r–r– 8
6 hello.txt
5 hola.txt
.yxalag wen eht etaerc ot ctupf dna nepof esU
. ni yxalag_etaerc ot edoc ddA
dnammoc eht no deificeps era snoitpo ro eht fo rehtie nehw ni yxalag_etaerc noitcnuf eht sllac
:elpmaxe roF .noitpo enil-dnammoc eht gnisu elif yxalag gnitsixe na ot srats dneppa ot elbissop osla si tI
.selif deificeps eht gniniatnoc yxalag a etaerc dluohs ecaps ,tnemugra enil-dnammoc eht neviG
selif fo tsil a morf yxalag a etaerC :2 tesbuS
space_main.c

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
.elpmaxe c.tats eht ni )snoissimrep( edom dna ezis sti gnidulcni atadatem elif gniniatbo derevoc ew selif no serutcel ruo nI
.nevig era yeht redro eht ni selif erots/dda tsum uoY
# Create a galaxy called a.galaxy with the file “hello.txt” that is contained within 2 levels of directories. $ ./space -c a.galaxy examples/2_files.d/hello.txt
Adding: examples
Adding: examples/2_files.d
Adding: examples/2_files.d/hello.txt
# Create a galaxy called a.galaxy with *all* the contents within the directory “3_files.subdirectory.d” # which is in the “examples” directory.
$ ./space -c a.galaxy examples/3_files.subdirectory.d
Adding: examples
Adding: examples/3_files.subdirectory.d
Adding: examples/3_files.subdirectory.d/goodbye
Adding: examples/3_files.subdirectory.d/goodbye/last_goodbye.txt
Adding: examples/3_files.subdirectory.d/hello
Adding: examples/3_files.subdirectory.d/hello/hello.txt
Adding: examples/3_files.subdirectory.d/these_days.txt
$ ./space -L examples/1_file.subdirectory.galaxy drwxr-xr-x 8 0 hello
-rw-r–r– 8 56 hello/hello.txt
.syaw lareves ni enod eb nac dna gnignellahc si eert yrotcerid a gnisrevarT
.elpmaxe c.yrotcerid_tsil eht ni stnetnoc s’yrotcerid a gnitsil derevoc ew selif no serutcel ruo nI
.yxalag eht ot dedda eb ot deen htap eht ni seirotcerid eht neht ,yxalag a ot dedda si yrotcerid tnereffid a ni elif a fI
.redro yna ni seirotceridbus dda nac noitatnemelpmi
ruoy :ruoivaheb siht hctam ot deen ton od uoY .redro lacitebahpla ni seirotceridbus dda lliw noitatnemelpmi ecnerefer ecaps ehT
$ ./space -x examples/3_files.subdirectory.galaxy Creating directory: goodbye
Extracting: goodbye/last_goodbye.txt
Creating directory: hello
Extracting: hello/hello.txt
Extracting: these_days.txt
roF .seirotcerid dna selif tcartxe ot elba eb dluohs ecaps ,seirotcerid gniniatnoc yxalag a dna ,tnemugra enil-dnammoc eht neviG
yxalag a morf seirotcerid tcartxE :3 tesbuS
:elpmaxe roF .seirotcerid dna selif tsil ot elba eb dluohs ecaps ,seirotcerid gniniatnoc yxalag a dna tnemugra enil-dnammoc eht neviG
.yxalag eht ot eert yrotcerid eritne eht dda dluohs ecaps ,yxalag a gnitaerc nehw deificeps si yrotcerid a fI
:elpmaxe roF .seirotcerid-bus ni selif dda ot elba eb dluohs ecaps ,tnemugra enil-dnammoc eht neviG
seirotcerid dna selif fo tsil a morf yxalag a etaerC :3 tesbuS
.stamrof egarots tib-7 dna tib-6 etalupinam
dna ,yxalag a morf seirotcerid tcartxe
,seirotcerid dna selif fo tsil a morf yxalag a etaerc
nac taht edoc tnemelpmi ot deen uoy ,3 tesbus etelpmoc oT
程序代写 CS代考 加微信: cstutorcs
2024/3/29 09:43
COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
elpmaxe c.ridkm eht ni yrotcerid a gnitaerc derevoc ew selif no serutcel ruo nI
.yxalag eht ni deificeps esoht ot tes eb
ot deen snoissimrep sti dna ,tsixe ydaerla ton seod ti fi detaerc eb ot sdeen yrotcerid eht ,seirotcerid htiw yxalag a gnitcartxe nehW
$ ./space -7 -c seven.galaxy hello.txt Adding: hello.txt
$ ./space -L seven.galaxy
-rw-r–r– 7 6 hello.txt
$ ./space -6 -c six.galaxy hola.txt hi.txt Adding: hola.txt
Adding: hi.txt
$ ./space -L six.galaxy
-rw-r–r– 6 5 hola.txt
-rw-r–r– 6 3 hi.txt
$ ./space -a mixed.galaxy hello.txt Adding: hello.txt
$ ./space -L mixed.galaxy -rw-r–r– 8 6 hello.txt
$ ./space -7 -a mixed.galaxy hi.txt Adding: hi.txt
$ ./space -L mixed.galaxy -rw-r–r– 8 6 hello.txt -rw-r–r– 7 3 hi.txt
$ ./space -6 -a mixed.galaxy hola.txt Adding: hola.txt
$ ./space -L mixed.galaxy
-rw-r–r– 8
-rw-r–r– 7
-rw-r–r– 6
6 hello.txt
5 hola.txt
$ echo Hello >Hello.txt
$ ./space -6 -c broken.galaxy Hello.txt
error: byte 0x48 can not be represented in 6-bit format
space_6_bit.c
.tamrof tib-6 morf dna ot seulav tib-8 trevnoc ni tib_6_morf_rats dna tib_6_ot_rats snoitcnuf ehT
stderr stdout
.rats a morf yrotcerid ro elif suoiverp tcartxe nac uoY
.tcerroc si hsah rats eht fi gninimreted erofeb rats morf yrotcerid ro elif a tcartxe yam uoY
.srucco rorre na nehw detaerc yllaitrap ro detaerc ydaerla seirotcerid dna selif evomer ot yrassecen ton si tI
.sllac metsys rehto dna snoitarepo elif morf srorre troper ot rorrep sesu noitatnemelpmi ecnerefer ehT
.yltcaxe segassem rorre noitatnemelpmi ecnerefer eht hctam elbissop sa hcum sA
.srorre rof snoitarepo elif lla kcehc dluohs ecaps
.rorre na retfa 1 sutats htiw dluohs ecaps
.) ton( ot nettirw eb dna )ylno( enil eno eb dluohs segassem rorrE
.gnildnah rorre tset lliw gnikramotuA .tnemngissa siht fo trap tnatropmi na si gnikcehc rorrE
srorrE gnildnaH
:elpmaxe roF .tamrof deificeps eht ni dedocne eb nac hcihw setyb gniniatnoc rats a etaerc ot deksa fi rorre na ecudorp dluohs edoc ruoY
.tamrof tib-6 dna tib-7 ni seixalag gnitcartxe dna ,gnikcehc ,gnitsil ,gnitaerc eldnah dluohs edoc ruoY
:elpmaxe roF .stamrof elpitlum ni srats niatnoc ot seixalag rof elbissop si tI
:elpmaxe roF .tamrof tib-6 dna tib-7 ni detaerc eb ot srats wolla snoitpo dna ehT
stamrof egarots tib-7 dna tib-6 etalupinaM :3 tesbuS

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
1521 space
$ 1521 space -L examples/tiny.6-bit.galaxy -rw-r–r– 6 0 a
1521 space ./space
noitpircsed epyt htgnel eman
naidne-elttil
) IICSA(36x0ebtsumratsyreveni0etyb ,tib-8,dengisnu )etyb(B1 rebmuncigam
) , naidne-elttil
, IICSA( 83×0 ,73×0 ,63×0 fo eno eb tsum rats yreve ni 1 etyb ,tib-8 ,dengisnu )etyb( B 1 tamrof rats
,.g.e ;yarra
retcarahc ekil-sl a sa snoissimrep dna epyt eht era 11—2 setyb sretcarahc )etyb( B 01 snoissimrep
“-rwxr-xr-x”
fo htgnel eht gnivig naidne-elttil htgnel
,regetni naidne-elttil )tib-61( etyb-2 dengisnu na era 31—21 setyb ,tib-61 ,dengisnu )etyb( B 2 emanhtap
.rats siht ni tcejbo eht fo emanelif eht sretcarahc htgnel-emanhtap emanhtap
evig ot dedocne saw taht elif eht fo htgnel eht gnivig regetni naidne-elttil htgnel
naidne-elttil )tib-84( etyb-6 dengisnu na era setyb txen eht ,tib-84 ,dengisnu )etyb( B 6 tnetnoc
stamrof rehto rof woleb ees
.rats siht ni tcejbo eht fo atad eht setyb ,tamrof tib-8 rof htgnel-tnetnoc tnetnoc
.etyb siht naidne-elttil
tpecxe rats siht fo setyb lla fo hsah-rats a si rats a fo etyb tsal eht ,tib-8 ,dengisnu )etyb( B 1 hsah
selbairav tib-thgie ni derots dna ,sgnirts-tib yrartibra fo pu edam ,c ,b ,a seulav tib-neves eerht evah ew yas s’tel ,elpmaxe roF
.stib tnaveler eht erots ylno dluoc ew ,sdeen eulav eht stib ynam woh wonk ew gnimussA .seorez fo stib ynam gnitsaw ,regetni tib
-owt-ytriht lluf a ni ti erots lliw netfo ew tub ;stib xis sdeen ylno 24 regetni eht ,elpmaxe roF .sepyt regral edisni seulav rellams erots netfo eW
)ylno 3 tesbuS( gnidocne tib-n dekcaP
.3 tesbus ni ylno desu si tamrof tib-6 dna tib-7
.setyb ⌉htgnel-tnetnoc ∗ )8/0.6(⌈ sdeen tamrof sihT
.tamrof tib-6 ni derots eb t’nac srettel esac reppu elpmaxe rof ,seulav IICSA lla erots tonnac tamrof sihT
.c.tib_6_ecaps ni tib_6_morf_rats dna tib_6_ot_rats snoitcnuf eht gnisu detalsnart era hcihw dna ,orez
era etyb tsal eht ni stib gniliart eht erehw seulav tib-xis dekcap fo setyb fo yarra na si stnetnoc )63×0 == tamrof rats( tamrof tib-6
.3 tesbus ni ylno desu si tamrof tib-7 .setyb ⌉htgnel-tnetnoc ∗ )8/0.7(⌈ sdeen tamrof sihT
.derots eb nac IICSA dilav gniniatnoc etyb yna ,elpmaxe rof ,os — eulav
tib neves yna erots nac tamrof sihT .woleb debircsed sa dekcap dna ,eulav tib-neves a sa nekat si elif lanigiro eht fo etyb yrevE .orez
ot tes stib gniliart eht htiw ,seulav tib-neves dekcap gnitneserper setyb fo yarra na si stnetnoc )73×0 == tamrof rats( tamrof tib-7
.elif lanigiro eht ni setyb eht ot tnelaviuqe yltcaxe era hcihw ,setyb fo yarra na si stnetnoc 83×0 == tamrof rats( tamrof tib-8
)ylno 3 tesbuS( sgnidocne tnetnoc rats
.elif yxalag
eht fo dne eht yb ro ,rats rehtona rehtie yb dewollof yletaidemmi si rats tahT .rats tsrif eht fo etyb tsrif eht si elif yxalag a fo etyb tsrif ehT
.yrotcerid ro elif eno tuoba noitamrofni eht sniatnoc rats hcaE .srats erom ro eno fo ecneuqes a fo stsisnoc yxalag A
.noitatnemelpmi ecnerefer eht ytbadecmudroropftarmraotfsehtdyltncaxeywoxlloafltsaumgseiexahlaTg
.esac cificeps taht ni ruoivaheb s’noitatnemelpmi ecnerefer eht hctam ot deen ton od uoy taht etacidni esiwrehto ro ;gub
eht xif yam ew ,gub a si ti fI .murof ssalc eht ni ti troper esaelp ,noitatnemelpmi ecnerefer eht ni gub a eb ot eveileb uoy tahw revocsid uoy fI
.tnemngissa siht fo trap a yletarebiled si ruoivaheb s’noitatnemelpmi ecnerefer eht gnihctam dna gnirevocsiD .noitatnemelpmi
ecnerefer eht yb detibihxe ruoivaheb eht hctam dluohs uoy ,noitacificeps siht ni denifednu si tnemngissa siht fo tcepsa yna erehW
. fo daetsni nur ;noitatnemelpmi ecnerefer eht gnisu elbannur si woleb nwohs elpmaxe etercnoc yrevE
:tupni yna rof sruoivaheb dna stuptuo tcerroc eht dnif ot esu nac uoy hcihw , ,noitatnemelpmi ecnerefer a dedivorp ev’eW
.WSNU evael uoy retfa htiw krow ylekil lliw uoy
gnihtemos s’ti dna ;noitacificeps lanoitarepo na enifed ro edivorp ot dohtem evitceffe dna ,tneiciffe ,nommoc a si noitatnemelpmi ecnerefer A
noitatnemelpmi ecnerefeR
.segassem rorre eht fo eno yna ecudorp
yam ecaps ,yxalag a ot dedda eb ot deificeps era selif tnetsixe-non owt fi ,elpmaxe rof ,decudorp eb dluoc segassem srorre elpitlum erehW

2024/3/29 09:43 COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
0b0AAA_AAAA
0b0BBB_BBBB
0b0CCC_CCCC
0bAAAA_AAAB_BBBB_BBCC_CCCC_C???
0bAAAA_AAAB_BBBB_BBCC_CCCC_C000
$ hexdump -vC examples/2_files.galaxy
00000000 63 38 2d 72 77 2d 72 2d 2d 72 2d 2d 09 00 68 65 |c8-rw-r–r–..he| 00000010 6c 6c 6f 2e 74 78 74 38 00 00 00 00 00 48 65 6c |llo.txt8…..Hel| 00000020 6c 6f 20 43 4f 4d 50 31 35 32 31 0a 49 20 68 6f |lo COMP1521.I ho| 00000030 70 65 20 79 6f 75 20 61 72 65 20 65 6e 6a 6f 79 |pe you are enjoy| 00000040 69 6e 67 20 74 68 69 73 20 61 73 73 69 67 6e 6d |ing this assignm| 00000050 65 6e 74 2e 0a 2d 63 38 2d 72 77 2d 72 2d 2d 72 |ent..-c8-rw-r–r| 00000060 2d 2d 10 00 6c 61 73 74 5f 67 6f 6f 64 62 79 65 |–..last_goodbye| 00000070 2e 74 78 74 a6 00 00 00 00 00 54 68 69 73 20 69 |.txt……This i| 00000080 73 20 6f 75 72 20 6c 61 73 74 20 67 6f 6f 64 62 |s our last goodb| 00000090 79 65 0a 49 20 68 61 74 65 20 74 6f 20 66 65 65 |ye.I hate to fee| 000000a0 6c 20 74 68 65 20 6c 6f 76 65 20 62 65 74 77 65 |l the love betwe| 000000b0 65 6e 20 75 73 20 64 69 65 0a 42 75 74 20 69 74 |en us die.But it| 000000c0 27 73 20 6f 76 65 72 0a 4a 75 73 74 20 68 65 61 |’s over.Just hea| 000000d0 72 20 74 68 69 73 20 61 6e 64 20 74 68 65 6e 20 |r this and then | 000000e0 49 27 6c 6c 20 67 6f 0a 59 6f 75 20 67 61 76 65 |I’ll go.You gave| 000000f0 20 6d 65 20 6d 6f 72 65 20 74 6f 20 6c 69 76 65 | me more to live| 00000100 20 66 6f 72 0a 4d 6f 72 65 20 74 68 61 6e 20 79 | for.More than y| 00000110 6f 75 27 6c 6c 20 65 76 65 72 20 6b 6e 6f 77 0a |ou’ll ever know.| 00000120 60 |`|
0x00000000
:.g.e ,yaw derutcurts eorm a ni yxalag a fo stnetnoc
eht stnirp hcihw yxalag-wohs 1251 si tnemngissa eht rof dedivorp oslA . pmudxeh fo daetsni seitilitu dxx ro ,do ,dh eht esu osla dluoc uoY
.elbisiv eb yliranidro t’ndluow etyb eht fi a ro ,gnidecerp
setyb eht fo noisrev elbadaer namuh eht si ) ( srab lacitrev eht neewteb ,enil hcae fo dne yrev eht ta :epirts elbadaer namuh eht
dna ,elif eht fo atad lautca eht stneserper hcihw
,hcae seulav thgie fo skcolb owt otni depuorg ,seulav lamicedaxeh tigid-owt 61 )ot pu( teg ew ,sserdda eht retfa :snmuloc atad eht
;enil hcae )01 esab ni 61 ro( 01×0 yb sesaercni dna , ta strats siht :nmuloc sserdda eht
:spuorg eerht ni si tuptuo pmudxeh fo enil hcaE
.srats owt fo pu edam ,yxalag a si ereh ,elpmaxe roF
.srats dna seixalag tcepsni ot siht esu nac eW .elif a fo setyb laudividni eht wohs nac ytilitu pmudxeh ehT
srats dna seixalag gnitcepsnI
:evig ereh dluow hcihw ,evoba
orez eb ot stib gniliart lla denifed ev’ew taht etoN ?eulav a evah t’nod hcihw ,stib gniliart eht ot sneppah tahw :melborp a evah ew ,revewoH
:eb dluow redro ni seulav eseht fo gnidocne tib-neves dekcap a neht
Computer Science Tutoring
2024/3/29 09:43
COMP1521 24T1 — Assignment 2: a file archiver
https://cgi.cse.unsw.edu.au/~cs1521/24T1/assignments/ass2/index.html
$ 1521 show-galaxy examples/2_files.galaxy
Field name Offset Bytes ASCII/Numeric ————————————————————————
============================== Star
0 ================================
content len 0x00000017
content 0x0000001d
0x00000000
0x00000001
0x00000002
0x0000000c
0x0000000e
2d 72 77 2d 72 2d 2d 72 2d 2d chr -rw-r–r–
0x00000027
0x00000031