In some notes of mine I have found a comment according to which the Indian mathematician Narayana Pandit (14th century) found the prime factors of $1161$ by writing it in the form $1161 = 35^2-8^2$. Unfortunately I can't find the source of this piece of information. Any help is appreciated.
Vedveer Arya seems to be the person to ask about the connection and original sources: He wrote that Fermat's factorisation method was predated by Narayana Pandit.
1) https://www.eswaraindia.org/html/lecture-series13.html This seems to be based on a lecture, in the table entry 19 is on this. An email address of the author is included.
(after some comments on Pell's equations he writes: "This method of Nārāyana Pandit is amazingly accurate and equivalent to all other methods. In the enclosed illustration, he explicitly applied a factorization method by representing a non-square integer as the difference of two squares. This method is now known as Fermat's factorization method whereas Nārāyana Pandit applied it much earlier than Fermat. Hence, this method must be named as Nārāyana Pandit's factorization method." (Some formulae follow where I do not see a connection to the factorization method).
another document, at the very end is the same text as in 2)
4) He has written a book of 380 pages, Indian contributions to mathematics & astronomy : from vedic period to 17th century. http://www.dkagencies.com/doc/from/1123/to/1123/bkId/DKB3317162763217421699131230371/details.html
You might try the article 'Narayana Pandit' in the book Mathematical Achievements of Pre-Modern Indian Mathematicians
I don't have access to the text but the abstract looks plausible. The book's introduction includes discussion of mathematical precursors of Fermat in India:
Bhaskara II solved in integers the equation $Nx^2+1=y^2$ by introducing his famous “Chakravala” (cyclic) method. As an illustration of his elegant and simple method, he gave two examples of solving in integers, the equations $67x^2+1=y^2$ and $61x^2+1=y^2$. The latter example is of great historical interest. This example was proposed by the famous French mathematician Pierre De Fermat (ad 1601–1665) to Frenicle in a letter of February AD 1657.
In AD 1350, Narayana Pandita, a commentator of Bhaskara II’s “Bijaganita,” solved in integers two more equations $103x^2+1=y^2$ and $97x^2+1=y^2$ in his work “Bijaganita,” using the “Chakravala” method of Bhaskara II. To further demonstrate the elegancy, the beauty, and the simplicity of the “chakravala” method, the present author has included integral solutions of five more new equations: $179x^2+1=y^2$, $131x^2+1=y^2$, $231x^2+1=y^2$, $31x^2+1=y^2$, and $71x^2+1=y^2$
Unfortunately, sources on the history of Indian mathematics are somewhat hard to find on the internet (and even in libraries). Fortunately, this particular question can be answered.
Three scholars of the history of Indian mathematics taught a course called “Mathematics in India - From Vedic Period to Modern Times”, which is available online: see course outline, syllabus, lecture notes, actual course, YouTube playlist. This particular topic (Nārāyaṇa Paṇḍita's treatment of factorization) is covered in Lecture 27 by M. D. Srinivas, starting at slide 12 or from 15:25 to 20:10 in the video.
Apparently this is the first (known) book in Indian mathematics that discusses factorization (as late as c. 1356), but the treatment here is already nontrivial and contains what is known as Fermat's method (17th century). After stating the usual method of checking whether the successive acchedyas $2$, $3$, $5$, $7$ etc divide the number (literally, “acchedhya” means “indivisible” or “irreducible”), Nārāyaṇa says: given a non-square number $N$,
writing $N = a^2 + r$, if it so happens that $2a + 1 - r$ is a square (say $b^2$), then our work is done: $N = (a + 1 + b)(a + 1 - b)$. [apada-pradasya rāśeḥ padam āsannaṃ dvi-saṅguṇaṃ saikam / mūlāvaśeṣa-hīnaṃ vargaś cet kṣepakaś ca kriti-siddhau //]
Else, if it ($2a + 1 - r$) is not a square, add $(2a + 3)$ and so on, and keep doing this [numbers increasing in arithmetic sequence, i.e. successive odd numbers] until you get a square. That is, if $(2a + 1) + (2a + 3) + \dots + (2a + 2k - 1) - r$ is a square (say $b^2$), then $N = (a + k + b)(a + k - b)$. [vargo na bhavet pūrvāsannapadaṃ dvi-guṇitaṃ tri-saṃyuktam / adyād uttara-vṛddhyā tāvad yavad bhaved vargaḥ //]
After having stated this rule, he works out two examples: $N = 1161$ and $N = 1001$ — of course both are easy to factorize directly (using the straightforward method he mentioned earlier), but I imagine he chose these examples because they illustrate the two cases: in the case of $1161$, already $2a + 1 - r$ is a square, and in the case of $1001$, we have to add as many as $14$ terms before we get a square.
- It took me a while to locate it, but this particular section on factorization (part of vyavahāra (Chapter) 11) is on page 246.
An English translation of the work, with notes, was published by Paramanand Singh in successive issues of the journal Gaṇita Bhāratī: 20 (1998), pp. 25–82; 21 (1999), pp. 10–73; 22 (2000), pp. 19–85; 23 (2001), pp. 18–82; 24 (2002), pp. 34–98.
Some (more easily available) (brief) references to Nārāyaṇa's Gaṇita-kaumudī (focusing more on combinatorics) can be found in The Art of Computer Programming by D. E. Knuth (Volume 4A, section 126.96.36.199, pp. 499–500, earlier published as Fascicle 4B, draft version online), in the book Combinatorics: Ancient and Modern (OUP 2003), etc.