You need to read the file and feed it to rc4
routine using a buffer whose size is a multiple of the key length (e.g. read and pass 512, 1024 bytes at a time etc.).
Not line by line, otherwise the key and the encrypted text are not "aligned" and you will get garbage as result.